list去重,String[]去重,String[]去空,StringBuffer去重,并且以','隔开,list拆分

list去重,String[]去重,String[]去空,StringBuffer去重,并且以','隔开,list拆分

 1.//  删除ArrayList中重复元素 
 public   static   void  removeDuplicate(List list)  {
    HashSet h  =   new  HashSet(list);
    list.clear();
    list.addAll(h);
    System.out.println(list);
}

2.// String[]去掉数组中重复的值
    public static String[] checkArr(String[] str) {
        for (String elementA : str) {
            System.out.print(elementA + " ");
        }
        List list = new ArrayList();
        for (int i = 0; i < str.length; i++) {
            if (!list.contains(str[i])) {
                list.add(str[i]);
            }
        }
        String[] newStr = list.toArray(new String[1]); // 返回一个包含所有对象的指定类型的数组
        return newStr;
    }

3.// 去掉String数组中的空值,形成新的String数组
String[] aa = {"","","ddd","","asdf" };
        List tmp = new ArrayList();
        for(String str:aa){
            if(str!=null && str.length()!=0){
                tmp.add(str);
            }
        }
        aa = tmp.toArray(new String[0]);

//.StringBuffer去重,并且以,隔开
    public StringBuffer check(List list, StringBuffer stringbuffer) {
        HashSet hashset1 = new HashSet(list);
        list.clear();
        list.addAll(hashset1);
        boolean flag = false;
        for (String item : list) {
            if (flag) {
                stringbuffer.append(",");
            } else {
                flag = true;
            }
            stringbuffer.append(item);
        }
        return stringbuffer;
    }

4。// 如果list太大,拆分list
            if (mylist.size() > 0) {
                int total = mylist.size() / 500;
                if (mylist.size() % 500 > 0) {
                    total++;
                }
                for (int i = 1; i <= total; i++) {
                    List lists = mylist.subList((i - 1) * 500,
                            i * 500 > mylist.size() ? mylist.size() : i * 500);
                    sysUserMapper.batchSave(lists);
                }
            }

 

posted @ 2019-04-02 09:44 A点点圈圈A 阅读( ...) 评论( ...) 编辑 收藏

你可能感兴趣的:(list去重,String[]去重,String[]去空,StringBuffer去重,并且以','隔开,list拆分)