JAVA去除集合中重复的元素

java去除集合中重复的元素

	public List<Check> removeExtra(List<Check> list) {
		List<Check> newList= new ArrayList<Check>();
        HashMap<String, String> hashMap = new HashMap<String, String>();
        for (Check check : list) {
            if (check == null) {
                continue;
            }
            String  Id = check.getId();
            if (Id != null) {
                String value = hashMap.get(Id);
                if (StringUtil.isEmpty(value)) { //如果value是空的  说明取到的这个Id是第一次取到
                    hashMap.put(Id, Id);
                    newList.add(check); 
                } else {
                    continue;
                }
            }   
        }
        hashMap.clear();
        return newList;
	}
	

猜你喜欢

转载自blog.csdn.net/qq_35029061/article/details/81430172