Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java collections

 
Mario A. Villamizar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I'm building an application where I need a collection to hold some objects of the same class. it can grows or decrease in size implementing insertions and deletions respectibly. duplicates are not allow.
I think I could use a set but I not sure how to use it, can you show me an example, or tellme which collection is it much better for the application.
As well I heard that the vector class was deprecated in j2se 1.4, is that true?
many thanks,
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a little crib sheet to help me remember which collection to use. See if the qualities listed match up with what you need to do and help you pick one. There is a tiny example of creating and filling a HashMap there, too. Hope that helps!
 
Charles Hasegawa
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a LinkedHashSet. If the objects that will be held are custom objects, make sure that the .equals and .hashCode methods are implemented correctly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic