欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

TreeMap的使用,TreeMap使用,import java.

来源: javaer 分享于  点击 8571 次 点评:225

TreeMap的使用,TreeMap使用,import java.


import java.util.Collections;import java.util.Iterator;import java.util.TreeMap;public class TestTreeMap {    public static void main(String[] args) throws Exception {        // 逆序        TreeMap<String, String> sortedMap = new TreeMap<String, String>(                Collections.reverseOrder());        // TreeMap<String, String> sortedMap = new TreeMap<String, String>();        sortedMap.put("20100804115500",                "1489625296 110010116   baoniu1155  0   1   20100804115500");        sortedMap.put("20101105102659",                "1489625296 179897693   baoniu  -1  1   20101105102659");        sortedMap.put("20101105102659",                "1489622000 179897693   Adennis1155 1   1   20101105102659");        sortedMap.put("20100804115500",                "1489625296 110010116   baoniu1155  1   0   20100804115500");        sortedMap.put("20110930120040",                "1489595111 65753805    dennis1155  -1  100 20100930120040");        sortedMap.put("20100930120041",                "1489595216 65753805    angle   -1  100 20100930120040");        sortedMap.put("title", "11 t tiel test");        sortedMap.put("cid", "22 t tiel test");        sortedMap.put("aategory", "33 t tiel test");        sortedMap.put("ii", "44 t tiel test");        System.out.println("first :" + sortedMap.get(sortedMap.firstKey()));        System.out.println("last :" + sortedMap.get(sortedMap.lastKey()));        Iterator<String> iter = sortedMap.keySet().iterator();        while (iter.hasNext()) {            Object key = iter.next();            Object value = sortedMap.get(key);            System.out.print("K: " + key);            System.out.println("    V: " + value);        }        System.out.println("======================");        Iterator<?> it1 = sortedMap.entrySet().iterator();        while (it1.hasNext()) {            System.out.println(it1.next());        }    }}//该片段来自于http://byrx.net
相关栏目:

用户点评