java参数,字典升序排列

时间:2015-03-11 14:32:18   收藏:0   阅读:1826

开发的这段时间,遇到过不同的一些接口,有些接口比较严谨,需要参数字典升序进行加密,因此编写了以下这个方法进行排序,采用存入map的方式,对他的key进行字典升序排列,返回有顺序的list。

 

public static List getCode(Map map){
    List list = new ArrayList();
    Iterator iter = map.entrySet().iterator();  //获得map的Iterator
      while(iter.hasNext()) {
        Entry entry = (Entry)iter.next();
        list.add(entry.getKey());
      }
    Collections.sort(list);
    return list;
}

 

随后可通过遍历list的下标,拿出值即可。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!