private static List getDiffrent(List list1, List list2) {
List diff =new ArrayList();
long start = System.currentTimeMillis();
Map map =new HashMap(list1.size() + list2.size());
List maxList = list1;
List minList = list2;
if (list2.size() > list1.size()) {
maxList = list2;
minList = list1;
}
for (String string : maxList) {
map.put(string,1);
}
for (String string : minList) {
Integer count = map.get(string);
if (count !=null) {
map.put(string, ++count);
continue;
}
map.put(string,1);
}
for (Map.Entry entry : map.entrySet()) {
if (entry.getValue() ==1) {
diff.add(entry.getKey());
}
}
System.out.println("耗时:" + (System.currentTimeMillis() - start) +" 毫秒");
return diff;
}
网友评论