• 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

Collections

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, when using Java collections, the choice of which collection to use in a particular situation is always data and requirements driven? We only use Map if the data is key-value pairs and we only use Set if we want no duplicates in our data? And, we use Trees if we want data sorted?

When retrieving data from a database and dealing with large amounts of data, we should generally lean towards Hash and Tree collections since their performance is best?

Thanks!
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Vikram.

It's best to consider collections from 2 points of view: as  abstracts and as concrete Java implementations.

For example, in Computer Science a Set is a collection of unique elements. A collection of non-unique elements is called a Bag, but Java doesn't actually have any specific Bag classes. So if you want unique values, look at the Collection classes with "Set" in their name. Note that that Maps only provide for unique keys - multiple keys can reference the same value! Abstractly speaking, Sets and Bags are unordered collections, but specific implementations in Java may include ordering. For example, java.util.List can be used as a Bag and it's ordered, by definition.

The basic ordered Collection is a List (or array). Trees are technically 2-dimensional constructs, but Java has several flavors of them, depending on whether they should display Set-like behavior or not. And so forth.
 
Vikram Sethi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim! That was very helpful!
reply
    Bookmark Topic Watch Topic
  • New Topic