• Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections Framework  RSS feed

 
Manu Dhanda
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone

Am at learning stage of java 'n am too puzzled about this framework. I don't know how to use it in a practical application? For ex. a HashTable, how do we use it in real practice? As we have databases to store 'n retrieve the data then where do we need to use this framework? Or do we use it between these two layers like this -

Application --> Hash Table -->Database

Or is it used totally independent of databases?

It would be great if someone can explain it with a simple example. Also, what makes it so important in Java?

Maybe for a few, it would be a funny question, but for me it's rather very important to clear my confusion.

Thanks.
Manu
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Imagine some user information in a DB: id, name, address
2. Imagine you have a web page with a combo box displaying the id only.
3. Select the user id and submit the page
How can you get simply the user information ? With a map.

For example, the map key is a String (user id) and the map value is the user information (User class)
Map users :
0001 -> (bob, Tokyo)
0002 -> (joe, London)
0003 -> (max, Paris)

If you select "0002" from the combobox, you can get this user's information quickly using the map
User user = (User)users.get("0002");

This is one practicle example. There are many more.
 
Z Sugiarto
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply, the collection frameworks are data structure. The simplest data structure are arrays.

What are arrays used for? to hold data... temporarily. You might display this data later to UI, or you might push it down the database. You might process it somehow, but the important thing is somewhere at one point in ur app u want to have a collection of data. So u use a data structure.

My suggestion is, easiest way u can pick up this stuff is by trying it.

So go play around with Vector. Open up your old code where you have used array, replace it with Vector. Then try to play around with Vector and see what sort of usage you can get out of it.

Once you understand Vector, it should be easy to understand the use of other data structure: HashSet, HashMap, LinkedHashSet, LinkedHashMap, ArrayList, etc. because they're basically the same shit.

Once u know how to USE em, then u better dig google to find what their IMPLICATIONS are. Which one is faster, which one consumes more memory, which one can store duplicate items, which one is good for storing certain data, etc.

hope that helps.
 
Manu Dhanda
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the information you both provided.
I got a direction 'n will try to implement it. Let's see where It takes me 'n will hit back with some new probz
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you do, please read [URL=http://faq.javaranch.com/view?UseReadWords[/URL]. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!