aspose file tools*
The moose likes Java in General and the fly likes HOW TO CREATE HASH MAP USING ARRAYLIST?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HOW TO CREATE HASH MAP USING ARRAYLIST??" Watch "HOW TO CREATE HASH MAP USING ARRAYLIST??" New topic
Author

HOW TO CREATE HASH MAP USING ARRAYLIST??

sanjeev katthi
Greenhorn

Joined: Jun 11, 2007
Posts: 19
1)How to create HashMap using ArrayList?
2) how to create hashmap without using any collection classes??
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

This sounds like homework. We tend to encorage people not to provide answers for homework questions. To that end, what do you think? Have you been through the Collections tutorial? Have you looked at the JavaDocs for ArrayList?


(Also, please don't post topic subjects in capital letters)


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Can you please explain your questions more clearly? Both questions sound a little bit strange.

An ArrayList is just a list of objects. A HashMap is a dictionary data structure; it allows you to store values that can be retrieved by keys, and the keys can be any kind of object. ArrayList and HashMap are two completely different things.

HashMap is one of Java's collection classes. So what do you mean with your second question? Do you want to create a HashMap without using a HashMap??


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
sanjeev katthi
Greenhorn

Joined: Jun 11, 2007
Posts: 19
hi..actually, this question was asked in a interview.. he asked me to write code to create hash map using arraylist. here in his sense, creating a key value pairs like hashmap using arraylist..
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You might have critiqued the question. A HASH map is a specific implementation of Map. Did he really want you to uses hashes? Or just to come up with your own implementation of Map? You'd have to guess whether he'd be impressed or insulted that you found the question ambiguous.

The latter is pretty easy ... a map has a bunch of keys and a bunch of values. Look at the Map API. Could you write those methods using lists to store keys and values?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HOW TO CREATE HASH MAP USING ARRAYLIST??
 
Similar Threads
In Struts,<logic:iterate> to iterate over values of hashmap which are arraylist of arraylists
Parsing a text file to an arraylist
How to link Hashmap and Arraylist
hash map.hash table....
Using Generics, HashMap with two different objects as Keys