- package cn.javastudy.demo1;
- import java.util.*;
- public class StringBufferDemo {
- public static void main(String[] args)
- {
- TreeMap<String, String> sort=new TreeMap<String,String>(new Comparator<String>(){
- @Override
- public int compare(String o1, String o2) {
- if(o1.equals(o2))
- return 0;
- if(o1.compareTo(o2)>0)
- return -1;
- else
- {
- return 1;
- }
- }});
- sort.put("6", "6");
- sort.put("5", "5");
- sort.put("3", "3");
- sort.put("1", "1");
- sort.put("2", "2");
- sort.put("4", "4");
- System.out.println(sort);
- }
- }
复制代码 |