Intersection and union of ArrayLists in Java

后端 未结 24 2497
离开以前
离开以前 2020-11-22 06:05

Are there any methods to do so? I was looking but couldn\'t find any.

Another question: I need these methods so I can filter files. Some are AND filter

24条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 06:57

    I was also working on the similar situation and reached here searching for help. Ended up finding my own solution for Arrays. ArrayList AbsentDates = new ArrayList(); // Will Store Array1-Array2

    Note : Posting this if it can help someone reaching this page for help.

    ArrayList AbsentDates = new ArrayList();//This Array will store difference
          public void AbsentDays() {
                findDates("April", "2017");//Array one with dates in Month April 2017
                findPresentDays();//Array two carrying some dates which are subset of Dates in Month April 2017
    
                for (int i = 0; i < Dates.size(); i++) {
    
                    for (int j = 0; j < PresentDates.size(); j++) {
    
                        if (Dates.get(i).equals(PresentDates.get(j))) {
    
                            Dates.remove(i);
                        }               
    
                    }              
                    AbsentDates = Dates;   
                }
                System.out.println(AbsentDates );
            }
    

提交回复
热议问题