Answer the question
In order to leave comments, you need to log in
Java, what is the best way to store objects?
I'm writing a simple application in Java and ran into the same problem. Objects need to be stored somewhere, for storage I chose HashMap in which I set String as a key, the key for each object matches its own name field, this gives us great accessibility - when communicating with the application through the console to change some object we can get it directly with the input name. But the problem arose with the renaming of the object. In this case, in theory, you will have to remove the key-object pair from the HashMap each time and place it again with a new name. And I really don't like this approach. How can you better get out of this situation?
Answer the question
In order to leave comments, you need to log in
It is basically impossible to change the value of a key. The one you don't like is the best one.
This is Java. Use the DAO pattern. (Data Access Object)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question