浅谈Java中Map和Set之间的关系(及Map.Entry)
package Demo;
import java.util.*;
import java.util.Map.*;
public class DemoMap {
public static void main(String[] args) {
text1();
System.out.println("=========================================================");
text2();
}
public static void text1(){
Map
DemoMap.put(4, "dddd");
DemoMap.put(1, "a");
DemoMap.put(3, "ccc");
DemoMap.put(2, "bb");
Collection
System.out.println("set=="+set);
Iterator
Map.Entry
while(it.hasNext()){
entry=it.next();
System.out.println("en.getKey()=="+entry.getKey());
System.out.println("en.getValue()=="+entry.getValue());
}
}
public static void text2(){
Map
DemoMap.put(4, "dddd");
DemoMap.put(1, "a");
DemoMap.put(3, "ccc");
DemoMap.put(2, "bb");
Iterator
Entry
while(set.hasNext()){
temp=set.next();
System.out.println("getKey()=="+temp.getKey());
System.out.println("getValue()=="+temp.getValue());
}
}
}