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<String> list = new ArrayList<String>();
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<String> tmp = new ArrayList<String>();
for(String str:aa){
if(str!=null && str.length()!=0){
tmp.add(str);
}
}
aa = tmp.toArray(new String[0]); //.StringBuffer去重,并且以,隔开
public StringBuffer check(List<String> list, StringBuffer stringbuffer) {
HashSet<String> hashset1 = new HashSet<String>(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<SysUserFormMap> lists = mylist.subList((i - 1) * 500,
i * 500 > mylist.size() ? mylist.size() : i * 500);
sysUserMapper.batchSave(lists);
}
}
05-26 03:50