import java.util.*;
class Test
{
public static void main (String[] args)
{
Map<String,String> m = new TreeMap<String,String>(new Comparator<String>(){
public int compare(String s1,String s2)
{
int num= s1.compareTo(s2);
return num;
}
});
m.put("乔峰","阿朱");
m.put("段誉","王语嫣");
m.put("虚竹","梦姑");
m.put("林","who");
Set<String> set = m.keySet();
for(String s:set)
{
System.out.println(s+" = "+m.get(s));
}
System.out.println("----------------------------------------");
Set<Map.Entry<String,String>> set1 = m.entrySet();
for(Map.Entry<String,String> en : set1)
{
if(en.getKey()=="3")
{
en.setValue("小");
}
System.out.println(en.getKey()+"="+en.getValue());
}
}
}
|
|