Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Map key or key in object?
nimo frey
Ranch Hand
Posts: 580
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What is better:
To use something like this:
private Map<String, MyObject> myObject= new HashMap<String, MyObject>(); // getter/setter
or is it better, to replace the String-Key of the Map as a property of MyObject, doing this, I can replace my Map to a List:
private List<MyObject> myObject= new ArrayList<MyObject>(); // getter/setter
What is better? When should I prefer the first one?
nimo frey
Ranch Hand
Posts: 580
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Oh, I guess I have to use the Map, as I cannot access a Object within the list directly.
In a map I can say:
myMap.get('mykey')
and it returns the corresponding object. If I put the key as a property in MyObject, then I cannot retrieve this object directyl:
myList.get(???).
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Struts with ValueObject in HashMap
java desing issue
jaxb hashmap?
List box initialization through managed bean
generic casting with object.getClass() ?
More...