notebook.java

来自「JAVA 入门小程序」· Java 代码 · 共 65 行

JAVA
65
字号

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 + =
减小字号Ctrl + -
显示快捷键?