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

  • Home
  • SEARCH
  • 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 7832979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:30:51+00:00 2026-06-02T12:30:51+00:00

While making my program i have come across this requirement that i have to

  • 0

While making my program i have come across this requirement that i have to assign unique id’s to some Objects that i create. Now i am creating the objects dynamically on GUI, and initially i used simple counter to assign int value to the created node, and it worked just fine.

However the problem that this approach creates is that if while creating the GUI, if some node has to be deleted, this id is also removed and is never used again. With the next new node, everytime i have to use the latest counter value and this creates lot of missing int values if nodes are deleted during the process.

I wanted to reuse those missing id’s upon creating of new nodes, for this i am confused which approach i should addopt.

MY Ideas:

  1. Using a ArrayList that contains the available values, plus if a node
    is deleted, it’s id is added to this list, i sort this list and use
    the minimum value for new node. Fine but, when i use this value, if
    i remove it from List, the index is not deleted and this causes
    problem.
  2. HashMap, similarly like above i add available id’s and remove not used, but not sure how to sort this hashMap???

Can you suggest how i should go about it? May be i need some kind of stack where i can push values, sort it and use the minimum value, and if that i used, it is removed from this stack, please give some ideas about this how to accomplish this task???

  • 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-02T12:30:53+00:00Added an answer on June 2, 2026 at 12:30 pm

    Keep a list of the deleted IDs, and when you create a new node, check that list for an ID to re-use (doesn’t matter which you take); if the list is empty (as it will be initially), get a new ID “the old way”. Even more clever: make the list an object that will generate a new ID if there aren’t any deleted ones in it, so the caller doesn’t have to worry about HOW the ID was arrived at.

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

Sidebar

Related Questions

I noticed while making a program that a lot of my int type variables
While making some final tests of a class-library that I'm writing for Windows Mobile
I'm making a program in Java that reads in some stuff from a file
Well, I have this bit of code that is slowing down the program hugely
I am making an application that does some custom image processing. The program will
I Have a java program that does sort of this: It starts off with
I am making this little program using command line arguments, I have like 90%
I'm starting with Ruby, and while making some test samples, I've stumbled against an
I am making a fighting game in Flash and while I have everything running,
I've been making small scale projects for a while now. I haven't started a

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.