Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:44:33+00:00 2026-06-15T10:44:33+00:00

I have two ArrayLists as shown – pinklist and normallist . I am comparing

  • 0

I have two ArrayLists as shown – pinklist and normallist. I am comparing both of them and finding the unique and duplicate values from both as shown below in code:

List<String> pinklist = t2.getList();
List<String> normallist = t.getList();
ArrayList<String> duplicatevalues = new ArrayList<String>();
ArrayList<String> uniquevalues = new ArrayList<String>();

for (String finalval : pinklist) {
    if (pinklist.contains(normallist)) {
        duplicatevalues.add(finalval);
    } else if (!normallist.contains(pinklist)) {
        uniquevalues.add(finalval);
    }
}

I am getting the duplicateValues properly, but I am not getting the unique values.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:44:34+00:00Added an answer on June 15, 2026 at 10:44 am

    You’re ignoring finalval in your conditions, instead asking whether one list contains the other list.

    You could do it like this:

    // Variable names edited for readability
    for (String item : pinkList) {
        if (normalList.contains(item)) {
            duplicateList.add(item);
        } else {
            uniqueList.add(item);
        }
    }
    

    I wouldn’t really call these “unique” or “duplicate” items though – those are usually about items within one collection. This is just testing whether each item from one list is in another. It’s more like “existing” and “new” in this case, I’d say.

    Note that as you’re treating these in a set-based way, I’d suggest using a set implementation such as HashSet<E> instead of lists. The Sets class in Guava provides useful methods for working with sets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrayLists and I am trying to subtract one arrayList from another.
So we have a java class with two ArrayLists of generics. It looks like
I have a two-dimension ArrayList that contains double values: ArrayList<ArrayList<Double>> data = new ArrayList<ArrayList<Double>>();
I have two classes (MVC view model) which inherits from one abstract base class.
I have implemented the two classes shown at http://tomcat.apache.org/tomcat-6.0-doc/aio.html which gives a messenger application
I have two arrays the store the values of two lines that are read
I've two issues currently preventing me from finishing two projects properly. I'll put them
I have two ArrayLists of different size. ArrayList<String> names = new ArrayList<String>(); ArrayList<User> users
I have two arraylists named fw_week and sw_week... Now have to calculate fw_diff which
I have two Arraylists: ArrayList a1 = new ArrayList(); a1.add(5); a1.add(10); a1.add(20); a1.add(50); a1.add(100);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.