• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Any Link Between ArrayList and HashMap

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends, Can you give few interview questions which relates ArrayList and Hashmap. I mean how to link ArrayList and HashMap.
 
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
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.
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList vs HashMap : I have stored objects in ArrayList , can i retrieve same objects in HashMap. is it possible?
 
Marshal
Posts: 80128
417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic