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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:14:35+00:00 2026-06-03T02:14:35+00:00

I am attempting to search for Member with a specific regNumber within a TreeSet.

  • 0

I am attempting to search for Member with a specific regNumber within a TreeSet. The regNumber however doesn’t have anything to do with the order of the elements in the TreeSet , which are ordered by last/first name.

The way I’m trying to do it now is to iterate through all the elements in TreeSet and return the element that matches the regNumber I am looking for. Is that good practice or is it too inefficient?

public class Members implements Comperable <Members> {

private String firstName;
private String lastName;
private int regNumber;

}

P.S the elements in the TreeSet must remain ordered by last/first name

  • 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-03T02:14:37+00:00Added an answer on June 3, 2026 at 2:14 am

    That fact that you are indexing by name and then searching by regNumber means that from the point of view of the regNumber you have an unordered collection of items. Therefore, you cannot do better than a linear search over all the items.

    If you want something better you could use the regNumber as a key in a hash table (HashMap or whatever) and have a reference to the original Member object as value. That way you can search more efficiently at the cost of using more space.

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

Sidebar

Related Questions

Attempting to build a C# NPAPI plugin I have found a tutorial which describes
I'm attempting to apply Ayende's order search from here to an existing index. The
I'm attempting to write a SQL search which will allow return any records which
I am attempting to search through an array list to find a value (which
I am attempting to do a search in Rails 3 like so. I have
I attempting to write a simple JQuery search. This is what I have so
I have a search query that I'm inheriting and attempting to optimize. I am
I have just spent all day attempting to get NHibernate.Search working alongside NHibernate 2.0
I am attempting to mimic the bing video search preview feature. I have a
We are attempting to use the Twitter Search Widget in our website: Twitter widget

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.