TreeMap的有序设计及实现

来源:互联网 发布:胎教讲故事软件 编辑:程序博客网 时间:2024/05/20 09:23
import java.util.*;public class TreeMapCheckTest{public static void main(String args[]){TreeMap test=new TreeMap(new MiyiComparator());test.put("z张三", 1356);test.put("l李四", 1257);test.put("z赵武", 1587);test.put("w王柳", 1985);test.put("y杨旭", 1563);System.out.println(test);System.out.println("------------------------");Set set=test.keySet();Iterator ite=set.iterator();while(ite.hasNext()){String str=(String)ite.next();if(str=="w王柳")test.put(str, new Integer(((Integer)test.get(str)).intValue()+1000));}ite=set.iterator();while(ite.hasNext()){String str=(String)ite.next();System.out.println(str+"= "+test.get(str));}}}class MiyiComparator implements Comparator{@Overridepublic int compare(Object o1, Object o2){// TODO Auto-generated method stubString str1=(String)o1;String str2=(String)o2;return str1.compareTo(str2);}}

0 0
原创粉丝点击