zoukankan      html  css  js  c++  java
  • 如果有两个list<Object>只取出两个中不重复的(还可以优化,这里计数器没做好,暂时使用第三变量)

    import java.util.*;

    class test2{

    public static void main(String[] args){
    	List<Integer> objList1 = new ArrayList<Integer>(); 
    	List<Integer> objList2 = new ArrayList<Integer>(); 
    	List<Integer> objList3 = new ArrayList<Integer>(); 
    	objList1.add(1);
    	objList1.add(2);
    	objList1.add(3);
    	objList2.add(1);
    	objList2.add(3);
    	objList2.add(4);
    	objList2.add(5);
    	objList1.addAll(objList2);
    	Set<Integer> set = new HashSet<Integer>();
    	
    	int t1 = objList1.size();
    	for(int i = 0;i<t1;i++){
    		boolean trueOrfalse  = set.add(objList1.get(i));
    		//System.out.println(objList1.get(i)+":"+trueOrfalse);
    		if(trueOrfalse==false){
    			objList3.add(objList1.get(i));
    		}
    	}
    	int t2 = objList3.size();
    	for(int j= 0 ;j<t2;j++){
    		set.remove(objList3.get(j));
    	}
    	System.out.println(set);
    }
    

    }

  • 相关阅读:
    Docker
    Alfred Workflow
    AWS Lambda
    XPath
    WebMagic
    Splash
    Selenium
    代理服务器
    JSONPath
    Sqlserver 查询分组 记录
  • 原文地址:https://www.cnblogs.com/kevinfuture/p/5169639.html
Copyright © 2011-2022 走看看