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 302631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:06:54+00:00 2026-05-12T07:06:54+00:00

This is mainly a performance questions. I have a master list of all users

  • 0

This is mainly a performance questions. I have a master list of all users existing in a String array AllUids. I also have a list of all end dated users existing in a String array EndUids.

I am working in Java and my goal is to remove any users that exist in the end dated array from the master list AllUids. I know PHP has a function called array_diff.

I was curious if Java has anything that will compare two arrays and remove elements that are similar in both. My objective is performance here which is why I asked about a built in function. I do not want to add any special packages.

I thought about writing a recursive function but it just seems like it will be inefficient. There are thousands of users in both lists. In order to exist in the end dated list, you must exist in the AllUids list, that is until removed.

Example:

String[] AllUids = {"Joe", "Tom", "Dan", "Bill", "Hector", "Ron"};

String[] EndUids = {"Dan", "Hector", "Ron"};

Functionality I am looking for:

String[] ActiveUids = AllUids.RemoveSimilar(EndUids);

ActiveUids would look like this:

{"Joe", "Tom", "Bill"}

Thank you all,
Obviously I can come up with loops and such but I am not confident that it will be efficient. This is something that will run on production machines everyday.

  • 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-12T07:06:54+00:00Added an answer on May 12, 2026 at 7:06 am

    Commons Collections has a class called CollectionUtils and a static method called removeAll which takes an initial list and a list of thing to remove from that list:

    Collection removeAll(Collection collection,
                         Collection remove)
    

    That should do what you want provided you use lists of users rather than arrays. You can convert your array into a list very easily with Arrays.asList() so…

    Collection ActiveUids = CollectionUtils.removeAll(Arrays.asList(AllUids), 
                                                      Arrays.asList(EndUids))
    

    EDIT: I also did a bit of digging with this into Commons Collections and found the following solution with ListUtils in Commons Collections as well:

    List diff = ListUtils.subtract(Arrays.asList(AllUids), Arrays.asList(EndUids));
    

    Pretty neat…

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

Sidebar

Related Questions

I have seen this mainly in the source of Facebook Bootloader.setResourceMap
I have found this example on StackOverflow: var people = new List<Person> { new
Am mainly looking at improving the performance of the query and also whether be
This is mainly a theoretical question i.e I don't have any need for a
This is mainly a performance issue. It is to help get the current average
There is an application with an extensive object graph. This graph mainly consists of
This error just started popping up all over our site. Permission denied to call
I've been doing some performance testing, mainly so I can understand the difference between
I'm interested in doing rapid app development in Python. Since this is mainly for
We have a large POSTGRESQL transactional database (around 70 million rows in all), and

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.