Created
September 1, 2014 10:51
-
-
Save vienhoang/7c067dd0004a6c3bb1de to your computer and use it in GitHub Desktop.
Java: HashMap
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
import java.util.HashMap; | |
public class Main { | |
public static void main(String[] args) { | |
// HashMap works like associate array | |
HashMap<String, String> map = new HashMap<String, String>(); | |
map.put("California", "Sacramento"); | |
map.put("Oregon", "Salem"); | |
map.put("Washington", "Olympia"); | |
System.out.println(map); | |
map.put("Alaska", "Juneau"); | |
System.out.println(map); | |
String cap = map.get("Oregon"); | |
System.out.println("The capitol of Oregon is " + cap); | |
map.remove("California"); | |
System.out.println(map); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment