import java.util.*; public class A { /** * @param args */ public static void main(String[] args) { Map<String,String> map = new HashMap<String,String>(); map.put("a","aa"); map.put("b","bb");
Set set = map.entrySet(); System.out.println(set);
believefym(feng) 讲得没错,而且api中也有一句话:The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. 其中believefym(feng)说的是通过map改变set,而以下就是通过SET 改变MAP(两者关联)import java.util.*; public class A { /** * @param args */ public static void main(String[] args) { Map map = new HashMap(); map.put("a","aa"); map.put("b","bb");
Set set = map.entrySet(); System.out.println(set); Iterator it=set.iterator(); it.next(); it.remove(); //未调用entrySet,下面的输出结果已经变了 //set=map.entrySet(); System.out.println(map); }}
public class A { /**
* @param args
*/
public static void main(String[] args) {
Map<String,String> map = new HashMap<String,String>();
map.put("a","aa");
map.put("b","bb");
Set set = map.entrySet();
System.out.println(set);
map.remove("a");
//未调用entrySet,下面的输出结果已经变了
System.out.println(set);
}}
其中believefym(feng)说的是通过map改变set,而以下就是通过SET 改变MAP(两者关联)import java.util.*;
public class A { /**
* @param args
*/
public static void main(String[] args) {
Map map = new HashMap();
map.put("a","aa");
map.put("b","bb");
Set set = map.entrySet();
System.out.println(set); Iterator it=set.iterator();
it.next();
it.remove();
//未调用entrySet,下面的输出结果已经变了
//set=map.entrySet();
System.out.println(map);
}}
你不用重新去再申明一次.