Skip to content

Instantly share code, notes, and snippets.

@vienhoang
Created September 1, 2014 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vienhoang/7c067dd0004a6c3bb1de to your computer and use it in GitHub Desktop.
Save vienhoang/7c067dd0004a6c3bb1de to your computer and use it in GitHub Desktop.
Java: HashMap
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