Tagged Questions
55
votes
8answers
59k views
Java - HashMap vs Map objects
What is the difference between the following maps I create (in another question, people answered using them seemingly interchangeably and I'm wondering if/how they are different):
HashMap<String, ...
42
votes
25answers
33k views
Java HashMap performance optimization / alternative
I want to create a large HashMap but the put() performance is not good enough. Any ideas?
Other data structure suggestions are welcome but I need the lookup feature of a Java Map:
map.get(key)
In ...
42
votes
4answers
48k views
map vs. hash_map in C++
I have a question with hash_map and map in C++. I understand that map is in STL but hash_map is not a standard. What's the difference of them two?
40
votes
12answers
58k views
Which data structure would you use: TreeMap or HashMap? (Java)
Description | A Java program to read a text file and print each of the unique words in alphabetical order together with the number of times the word occurs in the text.
The program should declare a ...
39
votes
4answers
18k views
Does Java have a HashMap with reverse lookup?
I have data that is organized in kind of a "key-key" format, rather than "key-value". It's like a HashMap, but I will need O(1) lookup in both directions. Is there a name for this type of data ...
27
votes
8answers
37k views
Convert JSON to HashMap using Gson in Java
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 ...
20
votes
7answers
18k views
How does Java order items in a HashMap or a HashTable?
I was wondering how Java orders items in the Map (HashMap or Hashtable) when they are added. Are the keys ordered by the hashcode, memory reference or by allocation precedence...?
It's because I've ...
17
votes
6answers
9k views
Java : Iteration through a HashMap, which is more efficient?
Given the following code, with two alternative ways to iterate through it,
is there any performance difference between these two methods?
Map<String, Integer> map = new ...
14
votes
5answers
5k views
HashMap to return default value for non-found keys?
Is it possible to have a HashMap return a default value for all keys that are not found in the set?
I am using Java.
9
votes
4answers
1k views
Convert an array of tuples into a hash-map in Clojure
I have an array of tuples, where each tuple is a 2 tuple with a key and a value. What would be the cleanest way to convert this array of tuples into a hash-map?
7
votes
4answers
99 views
java: maps zoo, what to choose
I'm pretty new to the Java World (since I'm writing primary in C/C++). I'm using maps in my apps.
Since java.util.Map is abstract I need to instantiate it's implementation. Usually I use HashMap like:
...
7
votes
2answers
657 views
Scala GroupBy preserving insertion order?
The groupBy method in Lists, Maps, etc., generate a Map after the function.
Is there a way to use the groupBy to generate a Map that preserves insertion order (LinkedHashMap, for instance)?
I'm ...
6
votes
4answers
10k views
How to putAll on Java hashMap contents of one to another, but not replace existing keys and values?
I need to copy all keys and values from one A HashMap onto another one B, but not to replace existing keys and values.
Whats the best way to do that?
I was thinking instead iterating the keySet and ...
6
votes
5answers
173 views
Can one control the identity of objects in Java, and if so, how?
This is a trivial programming question. I am not an expert in Java. Say I use objects of custom classes Company and Employee, in a manner similar to what many RDBMS examples do:
class Employee
{
...
6
votes
2answers
190 views
Is there a Map with a variable key length in Java world?
I need a Map but when I call get(key, n) it should should return not only all the records with the searched key value, but also all where the n last significant bits of the key are the same as the ...