📄 notebook.java
字号:
import java.util.*;
public class NoteBook
{
public static void main(String args[])
{
HashMap hm = new HashMap();
hm.put("a","11111111111");
hm.put("c","22222222222");
hm.put("b","33333333333");
hm.put("d","44444444444");
System.out.println("原始顺序");
System.out.println("姓名 电话");
Set s = hm.keySet();
Iterator it = s.iterator();
while(it.hasNext())
{
String name = (String)it.next();
System.out.print(name+" "+hm.get(name));
System.out.println();
}
TreeMap tm = new TreeMap(new Comparator(){
public int compare(Object o1,Object o2)
{
String s1 = (String)o1;
String s2 = (String)o2;
return s1.compareTo(s2);
}
});
tm.putAll(hm);
s = tm.keySet();
it = s.iterator();
System.out.println("升序");
System.out.println("姓名 电话");
while(it.hasNext())
{
String name = (String)it.next();
System.out.print(name+" "+hm.get(name));
System.out.println();
}
tm = new TreeMap(new Comparator(){
public int compare(Object o1,Object o2)
{
String s1 = (String)o1;
String s2 = (String)o2;
return -s1.compareTo(s2);
}
});
tm.putAll(hm);
s = tm.keySet();
it = s.iterator();
System.out.println("降序");
System.out.println("姓名 电话");
while(it.hasNext())
{
String name = (String)it.next();
System.out.print(name+" "+hm.get(name));
System.out.println();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -