zoukankan      html  css  js  c++  java
  • Java Map 排序取数

    View Code
     1 import java.util.Iterator;
    2 import java.util.Set;
    3 import java.util.TreeMap;
    4
    5 public class Test1 {
    6
    7 /**
    8 * @param args
    9 */
    10 public static void main(String[] args) {
    11 TreeMap<Integer,String> maps = new TreeMap<Integer,String>();
    12 maps.put(3, "王五");
    13 maps.put(1, "张三");
    14 maps.put(2, "李四");
    15 maps.put(4, "赵六");
    16
    17 // int size=maps.size();
    18 // int count=0;
    19 Set set=maps.keySet();
    20 Iterator iter=set.iterator();
    21 while(iter.hasNext()){
    22 Object key=iter.next();
    23 // if(count>=(size-2)){
    24 System.out.println(key+" "+maps.get(key));
    25 // }
    26 // count++;
    27 }
    28 }
    29 }
  • 相关阅读:
    函数式编程
    高级特性
    ZooKeeper介绍
    perl 退出函数问题
    perl 处理 回车 换行符
    定义函数
    调用函数
    python 字典
    python 条件判断
    列表和数组
  • 原文地址:https://www.cnblogs.com/jyluo03/p/2288768.html
Copyright © 2011-2022 走看看