[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Comparing 2 ArrayLists and extracting values which are not common

Posted on 2007-07-24
2
Medium Priority
?
1,412 Views
Last Modified: 2012-06-21
I have 2 ArrayLists

I want to compare them and extract uncommon items.
Basically want to get rid of common items.

Please guide
0
Comment
Question by:jaipur07
2 Comments
 
LVL 4

Accepted Solution

by:
NHBFighter earned 2000 total points
ID: 19556919
Here is a way,
            ArrayList al1=new ArrayList();
            ArrayList al2=new ArrayList();
            .......
            ArrayList unique=new ArrayList();
            for(int i=0;i<al1.size();i++){
                  if(!unique.contains(al1.get(i)))
                        unique.add(al1.get(i));
            }
            for(int i=0;i<al2.size();i++){
                  if(!unique.contains(al2.get(i)))
                        unique.add(al2.get(i));
            }
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 19557165
Implement Comparable or use a Comparator

http://www.exampledepot.com/egs/java.lang/Sortable.html?l=rel
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question