Comparing 2 ArrayLists and extracting values which are not common

Posted on 2007-07-24
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
Question by:jaipur07
    LVL 4

    Accepted Solution

    Here is a way,
                ArrayList al1=new ArrayList();
                ArrayList al2=new ArrayList();
                ArrayList unique=new ArrayList();
                for(int i=0;i<al1.size();i++){
                for(int i=0;i<al2.size();i++){
    LVL 86

    Expert Comment

    Implement Comparable or use a Comparator

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    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…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now