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

  • SEARCH
  • Home
  • 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 780775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:07:43+00:00 2026-05-14T20:07:43+00:00

I have two lists ( not java lists, you can say two columns) For

  • 0

I have two lists ( not java lists, you can say two columns)

For example

**List 1**            **Lists 2**
  milan                 hafil
  dingo                 iga
  iga                   dingo
  elpha                 binga
  hafil                 mike
  meat                  dingo
  milan
  elpha
  meat
  iga                   
  neeta.peeta    

I’d like a method that returns how many elements are same. For this example it should be
3 and it should return me similar values of both list and different values too.

Should I use hashmap if yes then what method to get my result?

Please help

P.S: It is not a school assignment 🙂 So if you just guide me it will be enough

  • 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-05-14T20:07:43+00:00Added an answer on May 14, 2026 at 8:07 pm

    EDIT

    Here are two versions. One using ArrayList and other using HashSet

    Compare them and create your own version from this, until you get what you need.

    This should be enough to cover the:

    P.S: It is not a school assignment 🙂 So if you just guide me it will be enough

    part of your question.

    continuing with the original answer:

    You may use a java.util.Collection and/or java.util.ArrayList for that.

    The retainAll method does the following:

    Retains only the elements in this collection that are contained in the specified collection

    see this sample:

    import java.util.Collection;
    import java.util.ArrayList;
    import java.util.Arrays;
    
    public class Repeated {
        public static void main( String  [] args ) {
            Collection listOne = new ArrayList(Arrays.asList("milan","dingo", "elpha", "hafil", "meat", "iga", "neeta.peeta"));
            Collection listTwo = new ArrayList(Arrays.asList("hafil", "iga", "binga", "mike", "dingo"));
    
            listOne.retainAll( listTwo );
            System.out.println( listOne );
        }
    }
    

    EDIT

    For the second part ( similar values ) you may use the removeAll method:

    Removes all of this collection’s elements that are also contained in the specified collection.

    This second version gives you also the similar values and handles repeated ( by discarding them).

    This time the Collection could be a Set instead of a List ( the difference is, the Set doesn’t allow repeated values )

    import java.util.Collection;
    import java.util.HashSet;
    import java.util.Arrays;
    
    class Repeated {
          public static void main( String  [] args ) {
    
              Collection<String> listOne = Arrays.asList("milan","iga",
                                                        "dingo","iga",
                                                        "elpha","iga",
                                                        "hafil","iga",
                                                        "meat","iga", 
                                                        "neeta.peeta","iga");
    
              Collection<String> listTwo = Arrays.asList("hafil",
                                                         "iga",
                                                         "binga", 
                                                         "mike", 
                                                         "dingo","dingo","dingo");
    
              Collection<String> similar = new HashSet<String>( listOne );
              Collection<String> different = new HashSet<String>();
              different.addAll( listOne );
              different.addAll( listTwo );
    
              similar.retainAll( listTwo );
              different.removeAll( similar );
    
              System.out.printf("One:%s%nTwo:%s%nSimilar:%s%nDifferent:%s%n", listOne, listTwo, similar, different);
          }
    }
    

    Output:

    $ java Repeated
    One:[milan, iga, dingo, iga, elpha, iga, hafil, iga, meat, iga, neeta.peeta, iga]
    
    Two:[hafil, iga, binga, mike, dingo, dingo, dingo]
    
    Similar:[dingo, iga, hafil]
    
    Different:[mike, binga, milan, meat, elpha, neeta.peeta]
    

    If it doesn’t do exactly what you need, it gives you a good start so you can handle from here.

    Question for the reader: How would you include all the repeated values?

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

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Register a ClassFileTransformer. Rather than modifying the bytes, record the… May 14, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer First, Dispatcher.BeginInvoke is only needed when you're on another thread… May 14, 2026 at 11:32 pm
  • Editorial Team
    Editorial Team added an answer Camtasia Studio is one such "de-facto" solution. May 14, 2026 at 11:32 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.