File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Any Link Between ArrayList and HashMap 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 "Any Link Between ArrayList and HashMap" Watch "Any Link Between ArrayList and HashMap" New topic
Author

Any Link Between ArrayList and HashMap

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
Hi Friends, Can you give few interview questions which relates ArrayList and Hashmap. I mean how to link ArrayList and HashMap.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I don't know what you mean by "how to link ArrayList and HashMap". Do you mean you want to know what the similarities and differences between these two are?

ArrayList and HashMap are both standard Java collection classes, but they have a different structure and a different purpose. An ArrayList is a an ordered sequence (a list) of objects backed by an array, and a HashMap is an associative array - a data structure that maps keys to values.

See Sun's Collections tutorial and The Collections Framework.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
ArrayList vs HashMap : I have stored objects in ArrayList , can i retrieve same objects in HashMap. is it possible?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
If you put the same objects into the HashMap, then you can retrieve them.

You appear to have misunderstood the two. It is a bit like asking whether you can use a boat or a bicycle. The answer is yes, but where boats work bicycles don't, and vice versa
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

You can put your ArrayList elements in a Map as follows:
The KeyType is usually something immutable like String, Integer or Long. The name of any object is often used. For instance:
Vice versa you have two options:
1) store map.entrySet() in the List
2) ignore the keys and store map.values() in the List.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Any Link Between ArrayList and HashMap
 
Similar Threads
Conversion In Collections
How to link Hashmap and Arraylist
can a arraylist be converted into HashMap?
struts 2 s:radio tag
Difference between HashMap and arraylist