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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:56:40+00:00 2026-05-28T18:56:40+00:00

My problem is very basic, but I have no clue how to solve it

  • 0

My problem is very basic, but I have no clue how to solve it correctly. I have a TreeSet which uses a comparator based on the name of the entity. However, I can change that name. How do I force a reordering of the TreeSet?

TreeSet<MyEntity> set = new TreeSet<MyEntity>(new BeanComparator("name"));
// bar < foo < xander
set.add(foo);
set.add(bar);
set.add(xander);
// resulting tree:     _-foo-_
//                   bar    xander
xander.setName("apple");

set.contains(xander); // -> false, since now neither 'foo' or 'bar' are equal to 'xander'

Is there some set.relayout() method I should be calling, or am I going about this all wrong?

  • 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-28T18:56:41+00:00Added an answer on May 28, 2026 at 6:56 pm

    If you have a link to the TreeSet when you changing the name of elements, just remove that element from the set, change its name, and insert back.

    If you don’t have that link at the time of updating name, then I’d suggest to have it as a private field in MyEntity, and rewrite setName() as

    public class MyEntity {
      private final TreeSet<MyEntity> container;
    
      ...
    
      public void setName(final String name) {
        container.remove(this);
        this.name = name;
        container.add(this);
      }
    }
    

    But, this approach is very ugly. You’d better avoid it.

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

Sidebar

Related Questions

I have a very basic texture map problem in GL on iPhone, and I'm
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
My problem must be very simple to solve for many of you but I
I realize that this is probably a very basic question, but I have spent
i have rather very basic question. I have one GUI class and another which
I have very basic understanding problem of Content types. I went through lot of
This may look a very basic question but I am having a problem accessing
I have written a very basic crawler which scrapes product information from websites to
I have a task tracking application, which is very basic. It currently has a
I am struggling with a very basic regex problem in my .htaccess file that

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.