Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HOW TO CREATE HASH MAP USING ARRAYLIST??

 
sanjeev katthi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)How to create HashMap using ArrayList?
2) how to create hashmap without using any collection classes??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
sanjeev katthi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic