Skip to content

Instantly share code, notes, and snippets.

@stathissideris
Created August 26, 2011 10:48
Show Gist options
  • Save stathissideris/1173178 to your computer and use it in GitHub Desktop.
Save stathissideris/1173178 to your computer and use it in GitHub Desktop.
Hash of hashes example in Java
package test;
import java.util.HashMap;
public class HashOfHashes {
public static void main(String[] args) {
//deep's type is a HashMap with String keys. Its values are Hashes with String keys and values
//Notice how you have to say all that twice, just to be sure :-/
HashMap<String, HashMap<String, String>> deep = new HashMap<String, HashMap<String, String>>();
HashMap<String, String> hashA = new HashMap<String, String>();
hashA.put("a", "a1");
hashA.put("b", "b1");
deep.put("hash A", hashA);
HashMap<String, String> hashB = new HashMap<String, String>();
hashB.put("a", "a2");
hashB.put("b", "b2");
deep.put("hash B", hashB);
//now the contents of deep are (in JSON):
//{
// "hash A" : {"a": "a1",
// "b": "b1"},
// "hash B" : {"a": "a2",
// "b": "b2"}
//}
}
}
@anopperl
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment