Skip to content

Instantly share code, notes, and snippets.

@ejknapp
Created February 16, 2011 21:34
Show Gist options
  • Save ejknapp/830274 to your computer and use it in GitHub Desktop.
Save ejknapp/830274 to your computer and use it in GitHub Desktop.
package java112.labs2;
import java.util.*;
/**
* @author Eric Knapp
* class MapDemo
*
*/
public class MapDemo {
public void run() {
Map<String, String> map = new HashMap<String, String>();
map.put("WI", "Wisconsin");
map.put("MI", "Michigan");
map.put("IL", "Illinois");
map.put("MN", "Minnesota");
map.put("FL", "Florida");
map.put("AK", "Alaska");
System.out.println(map);
Map<String, String> map2 = new TreeMap<String, String>(map);
System.out.println(map2);
Map.Entry entry = null;
Set set = map.entrySet();
//java 4
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
entry = (Map.Entry)iterator.next();
System.out.println(entry.getKey() + " = " + entry.getValue());
}
//java 5
for (Map.Entry<String, String> entry2 : map.entrySet()) {
System.out.println(entry2.getKey());
}
}
public static void main(String[] args) {
MapDemo demo = new MapDemo();
demo.run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment