Java List取交集差集



import java.util.*;

public class HelloWorld
{
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
        List<Long> freshClassList = new ArrayList<>();
            freshClassList.add(372L);
            freshClassList.add(373L);
            freshClassList.add(376L);
            freshClassList.add(379L);
            freshClassList.add(380L);
    
      
         List<Long> supContractClassList = new ArrayList<>();
            supContractClassList.add(373L);
            supContractClassList.add(3729L);
    
  
    
       // System.out.println(freshClassList.removeAll(supContractClassList));//true
      // System.out.println(freshClassList.size());//4
      
      System.out.println(freshClassList.retainAll(supContractClassList));//true
       System.out.println(freshClassList.size());//
  }
}

Jason.wang

When you find your talent can't afford to be ambitious, be quiet and study !

You may also like...