Mapの値を取得する方法
1668 ワード
public class Test {
public static void main(String args[]) {
// Map<String, String> emailsHashtable = new Hashtable<String, String>();
Map<String, String> emails = new HashMap<String, String>();
// : entrySet()
Iterator<Map.Entry<String, String>> its = emails.entrySet().iterator();
while (its.hasNext()) {
Map.Entry<String, String> m = (Map.Entry<String, String>) its.next();
System.out.println("email-" + m.getKey() + ":" + m.getValue());
}
// : entrySet(),
for (Map.Entry<String, String> m : emails.entrySet()) {
System.out.println("email-" + m.getKey() + ":" + m.getValue());
}
// : keySet()
Iterator<String> it = emails.keySet().iterator();
while (it.hasNext()) {
String key;
key = (String) it.next();
System.out.println("email-" + key + ":" + emails.get(key));
}
// :change the values of map to collection,and use the Collection.iterator() method.
/*
* Map aa = new Hashtable(); for (Iterator i = aa.values().iterator(); i.hasNext();) { Object temp = i.next(); }
*/
Map aa = new HashMap();
for (Iterator i = aa.values().iterator(); i.hasNext();) {
Object temp = i.next();
}
}
}