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
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
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(???).
It means our mission is in jeapordy! Quick, read this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
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...