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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:51:12+00:00 2026-05-25T18:51:12+00:00

I think this is an easy question, if I could figure out search terms

  • 0

I think this is an easy question, if I could figure out search terms to describe it. It’s similar to Finding all objects that have a given property inside a collection except I just want a Boolean “is it there” result.

Say I have a sorted TreeSet of Cats, each of which has a name, age, food, etc. I have something complicated to do for each potential cat name, but I want to skip it if there already a cat in my TreeSet with that name. I don’t care if any of the other attributes match. I obviously can’t do if (!AlltheCats.contains(candidateName))... because then I’ll have a type mismatch between the string candidateName and the object Cat. But I don’t think I can create an object to search for an identical match to, because I don’t care about the values for age, food, etc.

What would be an efficient/elegant way to do this?

  • 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-25T18:51:12+00:00Added an answer on May 25, 2026 at 6:51 pm

    Create a HashSet of Strings containing names, every time you invoke your method on a cat, check first if it is already in the set, and if it is, skip this cat. Modify this set as you keep going.

    (*)This answer assumes you want to invoke the method for one cat [and not 0] with identical name.

    Should look something like that:

        Set<String> names = new HashSet<String>();
        for (Cat c : set) { 
            if (names.contains(c.getName())) {
                continue;
            }
            names.add(c.getName());
            c.foo(); //your method here
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this could be a very easy question for you. But I have
I think this question should be something easy but after searching all over the
I think this is an overly easy question but my brain is failing to
I think this is a pretty easy question...How do I make a asp.net function
Ok, I think this is probably an easy question but for the life of
This feels like a too easy question to be found with google, I think/hope
I think this question is rather easy for you shell scripting monsters. I am
I thought this would be easy. The Google makes me think otherwise. What I
I would have thought that this would be an easy thing to do, but
(I think this is a pretty basic question on OOP, but unfortunately I wasn't

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.