• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HOW TO CREATE HASH MAP USING ARRAYLIST??

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)How to create HashMap using ArrayList?
2) how to create hashmap without using any collection classes??
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic