Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections Question

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you think of any opportunities to use a list or a map?
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please provide me with code scenario examples ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from these scenarios ,any more illustrations please
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic