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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:34:17+00:00 2026-06-02T10:34:17+00:00

In Java is there something similar to C++ Standard Library lists that uses a

  • 0

In Java is there something similar to C++ Standard Library lists that uses a comparator to find a specific object in a list by one of its variables?

For instance instead of looping through an ArrayList looking for a specific Object by checking for the variable comparison. Is there a way to use a comparator object to find a specific instance?

(Note: I don’t want to use a hashmap as that would create two seperate lists. I want the functionality of a list without having to have a hashmap involved.)

Something like this, but for Java:

#include <algorithm>

using namespace std;

class Cperson     
{    
  string lastname, firstname, address, city;    
  int zipcode;    
  char state[3];    
  // this works for the last name    
  friend bool operator==(const Cperson& left, const Cperson& right);    
  friend bool firstEqualTo(const Cperson& left, const Cperson& right);    
};

bool operator==(const Cperson& left, const Cperson& right)    
{    
  return left.lastname == right.lastname;    
}

bool firstEqualTo(const Cperson& left, const Cperson& right)    
{    
  return left.firstname == right.firstname;    
}     

Now we can search our personlist on the firstname field, ignoring the other fields:

vector<Cperson> personlist;    
// fill personlist somehow

Cperson searchFor;   // should contain the firstname we want to find    
vector<Cperson>::iterator fperson;   
fperson= std::find(personlist.begin(),    
                   personlist.end(),   
                   searchFor,    
                   firstEqualTo);
  • 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-02T10:34:20+00:00Added an answer on June 2, 2026 at 10:34 am

    If you can use Google Guava have a look at that question and its answers: Filtering on List based on one property with guava

    Update:

    If you don’t like Google and thus don’t want to use their libraries, try Apache Commons Collections’ CollectionUtils:

    List<Person> filteredList = new ArrayList<Person>(allPersons);
    CollectionUtils.filter( filteredList, new Predicate() {
      boolean evaluate(Object object) {
        //do whatever you want
      }
    });
    

    The downside is that Commons Collections itself doesn’t use Generics. There is a generic port of Commons Collections 3.1, however.

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

Sidebar

Related Questions

Is there something similar to java's InvocationHandler in vala. That is, I want to
Spring has PropertyPlaceholderConfigurer . Is there something similar that uses beans instead of property
Java has Collections.singletonList(T) which returns a List<T> of exactly one element. Is there something
In Java is this nice tool called FindBugs . Is there something similar in
Is there a way to shorten type names in java. Something similar to typedef
Is there something like python's interactive REPL mode, but for Java? So that I
Is there some easy way to pad Strings in Java? Seems like something that
Is there something similar to setting -D javax.net.debug=ssl at the command line for Java
I'm curious to know if there's something similar to the Task Parallel Library from
Is there something similar to Java/.NET serialization for C++?

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.