What is the most straightforward way to create a hash table (or associative array...) in Java? My google-fu has turned up a couple examples, but is there a standard way to do this?
And is there a way to populate the table with a list of key->value pairs without individually calling an add method on the object for each pair?
...
What is the difference between a hashmap and a hashtable in Java, and which is more efficient for non-threaded applications?
...
There is a case where a map will be constructed, and once it is initialized, it will never be modified again. It will however, be accessed (via get(key) only) from multiple threads. Is it safe to use a java.util.HashMap in this way?
(Currently, I'm happily using a java.util.concurrent.ConcurrentHashMap, and have no measured need to im...
One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hashmap? If not, what is it?
...
When I iterate over the values or keys are they going to correlate? Will the second key map to the second value?
...
I have recently run across these terms few times but I am quite confused how they work and when they are usualy implemented?
...
Hi guys,
I'm used to working with PHP but lately I've been working with Java and I'm having a headache trying to figure this out. I want to save this representation in Java:
Array (
["col_name_1"] => Array (
1 => ["col_value_1"],
2 => ["col_value_2"],
...
With a TreeMap it's trivial to bypass the keys' natural ordering using a Comparable.
HashMaps however cannot be controlled in this manner.
I suspect it would be both easy and useful to design an interface and to retrofit this into HashMap (or a new class)? Something like this, except with better names:
interface Hasharator<T> {
...
Suppose I have a hash_map and a code like
// i is an iterator
i = hash_map.erase(i)
But GCC's STL doesn't return iterator in erase, but a void. Now is a code like
hash_map.erase(i++)
safe (i.e. does not invalidate the iterator or does any other unexpected or unpleasant things)? Please note this is a hash_map.
...
I am trying to insert about 50,000 objects (and therefore 50,000 keys) into a java.util.HashMap<java.awt.Point, Segment>. However, I keep getting an OutOfMemory exception. (Segment is my own class - very light weight - one String field, and 3 int fields).
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java...
Something happened that I'm not sure should be possible. Obviously it is, because I've seen it, but I need to find the root cause & I was hoping you all could help.
We have a system that looks up latitude & longitude for a zipcode. Rather than access it every time, we cache the results in a cheap in-memory HashTable cache, since the l...
I'm trying to use TJCLHashMap family of classes, but apparently this class has no useful public methods. All methods are "protected". How to use this class? Although JCL comes with some samples, I seem to miss something. A basic example would be great.
...
I wrote a C++ project in VS2005, and used lots of STL container with its plus-in STL. However, I found STL in VS2005 does not have a hash_map in it, I want to use SGI hash_map. How can I change my project to use SGI STL?
Thanks for Brian's method, it works! And it's simple.
...
I know there is a WeakHashMap in java.util, but since it uses WeakReferences for everything, which is only referenced by this Map, referenced objects will get lost on the next GC cycle. So it's nearly useless if you want to cache random data, which is very likely to be requested again without being Hard-linked the rest of the time. The b...
I'm relatively new to C++. In Java, it's easy for me to instantiate and use a hashmap. I'd like to know how to do it in a simple way in C++, since I saw many different implementations and none of them looked simple to me.
...
What does Java use as a default probing method for HashMap? Is it Linear? Chaining or something else?
...
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 variable of type Map<String, Integer> to store the words and corresponding frequency of occurrence. Which concrete type, though? TreeMap<St...
I have a variable of type Hashmap<String,Integer>.
In this, the Integer value might have to go some manipulation depending upon the value of a flag variable. I did it like this...
Hashmapvariable.put( somestring,
if (flag_variable) {
//manipulation code goes here
new Integer(manipulated value);
} else {
new Integ...
Did you know that :
Map<Object,Object> m1 = new HashMap<Object, Object>();
Map<Object,Object> m2 = new HashMap<Object, Object>();
System.out.println("m1.equals(m2) = "+m1.equals(m2));
System.out.println("m1.keySet().equals(m2.keySet()) = "
+m1.keySet().equals(m2.keySet()));
System.out.println("m1.entrySet().equals(m2.entrySe...
I am trying to use the SGI STL implementation I have downloaded from their site. I want to use a hashmap, because I have to store around 5.000.000 records, but it should be good: I need to be able to access it very quickly. I've tried stedext::hash_map, but it was very slow because I couldn't set the initial size. By the way, is it possi...