Created
February 16, 2011 21:34
-
-
Save ejknapp/830274 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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