Java中List 去掉重复的值,并保持原先List顺序
1 2 private List<YourBean> removeDuplicate(List<YourBean> list) { 3 Set<YourBean> set = new HashSet<YourBean>(); 4 List<YourBean> newList = new ArrayList<YourBean>(); 5 for (Iterator<YourBean> iter = list.iterator(); iter.hasNext();) { 6 YourBean element = (YourBean) iter.next(); 7 if (set.add(element)) 8 newList.add(element); 9 } 10 return newList; 11 }