hashmap

Java multikeymap put-method

I want to implement the put and get-methods for a multikeymap in Java with two keys pointing to a value. I have written the put-method like this: public ValueType put(KeyTypeA key1, KeyTypeB key2, ValueType value) { HashMap<KeyTypeB, ValueType> mappi = outerMap.get(key1); ValueType oldvalue; if (mappi.containsKey(key2)) { oldvalu...

Can I use HashMaps in J2ME?

I cannot find much documentation about HashMaps in j2me. Does anyone have experience with this? How to create a HashMap? Map map1 = new HashMap(); should work, right? ...

Order of values retrieved from a HashMap

Hi all, 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 static void main(String[] args) { HashMap<Integer, String> hashmap = new HashMap<Integer, String>(); hashmap.put(1, "appl...

Bidimensional Hashmaps in Java (and in general)

Hello, which is the best way to write a bidimensional hashmap efficiently in Java? Just to give an example of what I'm talking about: I'm developing some algorithms related to collective intelligence, these algorithms works by calculating correlation between pairs of elements.. Without caching these values, since they are calculated on...

Why does HashSet implementation in Sun Java use HashMap as its backing?

Looking at the source of Java 6, HashSet<E> is actually implemented using HashMap<E,Object>, using dummy object instance on every entry of the Set. I think that wastes 4 byte (on 32-bit machines) for the size of the entry itself. But, why is it still used? Is there any reason to use it besides making it easier to maintain the codes? ...

HashMap collision

When there is a collision during a put in a HashMap is the map resized or is the entry added to a list in that particular bucket? ...

Collection.synchronizedMap vs synchronizing individual methods in HashMap

What is the difference between a Collections.synchronizedMap() and a wrapper around a HashMap with all the methods synchronized. I dont see any difference becuase Collections.synchronizedMap() internally maintains the same lock for all methods. Basically, what is the difference between the following code snippets Class C { Obje...

What is wrong with this Java code? Why can't I put in HashMap?

class{ public HashMap<String, String> eachperson; apple(){ this.eachperson.put("thekey","thevalue"); } } (Please excuse the public/privates in front of the class and function. I just want to know if I'm putting the hash map correctly. ) For the true code, please see below: class ParsedDataSet{ public HashMa...

HashMap for noobs - compilator "cannot find symbol - method get(java.lang.string)"

Hi I can't find a solution on this by myself. Please give me a tip or something import java.util.*; import java.io.*; class Fulgleinfluens { public static void main(String[] args) { HashMap <String, Komm> Komm = new hashMap<String, Komm>(); int teller = 0; try { Scanner Fil...

Convert Hash Map to 2D Array

What is the easiest way to convert a HashMap into a 2D array? ...

For general cases, when either one would work, which is better to use, a hashmap or a hashtable?

I've used hash tables occasionally in a couple of languages, but I just came across the Java map while browsing through some code. I checked up the differences in this SO question, which expressed it very clearly. My question is this: When either one could work for you , which is better to use? Which one should you choose if you're no...

HashMap null keySet

Hi, I am trying to loop over an HashMap with the keySet as below: for (String key : bundle.keySet()) { String value = bundle.get(key); ... } I use a lot of for-each loops on HashMaps in other parts of my code, but this one as a weird behavior: its size is 7 (what's normal) but keySet, entrySet and values are null (according t...

stl hash_map - modifying key

I have a hash map defined as class KeyType { int key; mutable bool flag; KeyType(int key) : key(key), flag(false) {} void setFlag() const { flag = true; } }; struct KeyType_hasher { size_t operator()(const KeyType& s) const { return static_cast<size_t> key; } }; struct KeyType_equal { size_t operat...

java hashmap values gone after rehash ?

I have the following piece of code : private static HashMap<String, TestObject> labelHash= new HashMap<String, TestObject>(); private static HashMap<String, TestObject> valueHash= new HashMap<String, TestObject>(); private HashMap getChildrenInHash(int opt){ // HashMap labelHash= new HashMap(); // HashMap valueHash=...

Comparing HashMaps in Java

I have two HashMaps: FOO & BAR. HashMap FOO is a superset of HashMap BAR. How do I find out what 'keys' are missing in HashMap BAR (i.e. exists in FOO but not BAR)? ...

Converting javafx.util.Properties to a HashMap

Hello, I was wondering if there is an easy way to convert the javafx.util.Properties object to a java.util.HashMap. There is the obvious way of getting each value from the Properties object and putting it in a Map. But with a large number of properties it seems like there should be a way of just getting the Map that backs javafx.util.P...

Java.util.HashMap -- why HashMap extends AbstractMap and implement Map ?

why HashMap extends AbstractMap and implement Map ? is extending AbstractMap not sufficient, because AbstractMap implements Map? ...

Hash Maps with <Key,Value>

I write: public interface Map <Key, Value> cells; eclipse complains and says "{ expected". public interface Map <Key, Value> cells{}; I then write the above in eclipse and it complains "Syntax error on token "cells", delete this token". What on earth should i do? Google is not my friend here as i can't find code snippets to work o...

The difference between python dict and tr1::unordered_map in C++

I have a question related to understanding of how python dictionaries work. I remember reading somewhere strings in python are immutable to allow hashing, and it is the same reason why one cannot directly use lists as keys, i.e. the lists are mutable (by supporting .append) and hence they cannot be used as dictionary keys. I wanted to...

Iterate Hash Map

I have an hashmap declared as private HashMap testMessages = null; I will be storing string values in both key and value part of the hashmap retrieved from oracle table. I am not concerned about the hashmap keys. I want to retrieve the hashmap values alone and check whether string variable filename is prefixed with one of the hash ma...