All Questions

2894
votes
38answers
1143906 views

Differences between HashMap and Hashtable?

What are the differences between a HashMap and a Hashtable in Java? Which is more efficient for non-threaded applications?
2618
votes
7answers
2858910 views

Iterate through a HashMap

Possible Duplicate: How do I iterate over each Entry in a Collection Map? What's the best way to iterate over the items in a HashMap?
340
votes
30answers
608506 views

Java Hashmap: How to get key from value?

If I have the value "foo", and a HashMap<String> ftw for which ftw.containsValue("foo") returns true, how can I get the corresponding key? Do I have to loop through the hashmap? What is the best...
171
votes
16answers
165381 views

How does a Java HashMap handle different objects with the same hash code?

As per my understanding I think: It is perfectly legal for two objects to have the same hashcode. If two objects are equal (using the equals() method) then they have the same hashcode. If two object...
126
votes
2answers
173449 views

How to loop through a HashMap in JSP?

How can I loop through a HashMap in JSP? <% HashMap<String, String> countries = MainUtils.getCountries(l); %> <select name="country"> <% // Here I need to loop ...
196
votes
12answers
217852 views

How can I convert JSON to a HashMap using Gson?

I'm requesting data from a server which returns data in the JSON format. Casting a HashMap into JSON when making the request wasn't hard at all but the other way seems to be a little tricky. The JSON ...
86
votes
13answers
286259 views

How to sort a HashMap in Java

How are we able to sort a HashMap<key, ArrayList>? I want to sort on the basis of a value in the ArrayList.
41
votes
5answers
68281 views

Is the order of values retrieved from a HashMap the insertion order

I am trying figure out the order in which the values in a HashMap are/can be retrieved. Heres the code snippet for the same. import java.util.HashMap; public class HashMapExample { public stati...
243
votes
17answers
422095 views

JavaScript Hashmap Equivalent

As made clear in update 3 on this answer, this notation: var hash = {}; hash[X] does not actually hash the object X; it actually just converts X to a string (via .toString() if it's an object, or s...
38
votes
7answers
14388 views

Are mutable hashmap keys a dangerous practice?

Is it bad practice to use mutable objects as Hashmap keys? What happens when you try to retrieve a value from a Hashmap using a key that has been modified enough to change its hashcode? For example,...

Previous Next