File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes How to make a HashMap index based Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "How to make a HashMap index based" Watch "How to make a HashMap index based" New topic
Author

How to make a HashMap index based

sakthi moorthy
Ranch Hand

Joined: Oct 17, 2007
Posts: 54
HI All,

I came across this question in an interview, how do you make a HashMap as index based like ArrayList. for example the way you insert the elements in the HashMap has to be same as the Way you retrieve elements in the HashMap.

The Answer given by me is "always return the same hashCode so that hashCollision occurs and all the elements will be saved in same bucket." still its not maintaing the index. is there any way to make HashMap index based.
Don Redd
Ranch Hand

Joined: Jan 05, 2012
Posts: 82

as per my knowledge , if you want to maintain insertion order you can use java.util.LinkedHashMap
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to make a HashMap index based
 
Similar Threads
collections help
compare two arraylists and get position of common elements
Retrieval of elements in Set
Regarding HashMap
permutations