This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Collections Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Collections Question" Watch "Collections Question" New topic
Author

Collections Question

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Ranchers,

In which scenario can i use the below Collections (can you give me a real time example where i can apply the below Collections Frammework and Why ?)

a>ArrayList
b>Linked List
c>Vector
d>HashMap
e>HashTable
f>Queue


When The Going Gets Tougher,The Tougher gets Going
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Deepak Lal wrote:In which scenario can i use the below Collections (can you give me a real time example where i can apply the below Collections Frammework and Why ?)

a>ArrayList
b>Linked List
c>Vector
d>HashMap
e>HashTable
f>Queue


Hello! Your post shows a homework vs interview vs certification question, but you haven't shown your thoughts on a solution yet, and this is critical in helping us identify what you know and what you're confused on. Please read these sections of the FAQ for more on this: ShowSomeEffort, DoYourOwnHomework, NotACodeMill, TellTheDetails

Best of luck!
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

I know the below concepts,BUT i want to know some REAL TIME EXAMPLES for the below where they can be used.

a>ArrayList -- Unsynchronized Data Structure
b>Linked List is based on Doubly linked List Data Structure
c>Vector -- Synchronized Data Structure
d>HashMap -- Unsynchronized Data Structure
e>HashTable -- Synchronized Data Structure
f>Queue -- Based on Dequeue Data Structure

I wanted some real time scenarios where the above said Collections can be applied in Java Based Applications.Could you please advice/Suggest now.?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Can't you think of any opportunities to use a list or a map?
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
Can't you think of any opportunities to use a list or a map?


Map:-
Use map when you want to store only unique elements like
two table are there emp_table with emp_id(primary key) and bank account with acc# (primary_key)

create a map for this such that 1emp_id corresponds to 1 or more acc# because an emplyoee can have mulitple bank accounts but an account cannot be corresponds to more than 1 emp_id

List:-
When to just want to add elements (can be duplicate elements) . you have indexed of these elements in your hand . resizable array


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Could you please provide me with code scenario examples ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

A list of employees that have signed up for a seminar. That's an example of a list.

A map of employees to their office/cubicle information (like number of ethernet connections and their IPs, location, etc.). That's an example of a map.
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Apart from these scenarios ,any more illustrations please
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3606
    
  60

Deepak,

these are actually very basic data structures that should be known to any programmer and they exist since the dawn of programming. There is nothing really special about them. It is a bit like asking illustrations for the use of + or * operators. Which scenario is best to illustrate multiplication?

There are hundreds of Lists, Sets or Maps in my current project. However none of them is so special as to serve as a good illustration, better than simple description 'this is a list of contracts', 'this is a map of customer ids to customers' or 'this is a set of refused identifiers'. However, to get the basic image, I'd strongly suggest to thoroughly read this tutorial: http://download.oracle.com/javase/tutorial/collections/interfaces/index.html. (I read this myself when I started using Java.)

The best way to get familiar with these structures is to use them in real code. If you have a question then, it will probably be 'which data structures to use in this situation I have', and that would be probably answered pretty well on this forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Collections Question
 
Similar Threads
Collection, Collections, Java Collections Framework
With JPA how can I force loading of nested lazy collections?
Exception with the available Buffer
Collections
mapping collections in hibernate