Created
August 26, 2011 10:48
-
-
Save stathissideris/1173178 to your computer and use it in GitHub Desktop.
Hash of hashes example in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} | |
//} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks