java List<Item> its=new ArrayList<Item>(); Map按value中的某字段排序
public List<Item> getAllItem(){
Map<Long, Item> itemDic = new HashMap<Long, Item>();
List<Map.Entry<Long, Item>> entryList = new ArrayList<Map.Entry<Long, Item>>(itemDic.entrySet());
if(entryList.size()>0){
List<Item> its=new ArrayList<Item>();
Collections.sort(entryList, new Comparator<Map.Entry<Long, Item>>() {
public int compare(Map.Entry<Long, Item> it1, Map.Entry<Long, Item> it2) {
return (it1.getValue().getType() - it2.getValue().getType());//根据value排序
}
});
for (int i = 0; i < entryList.size(); i++) {
its.add(itemDic.get(entryList.get(i).getKey()));
}
System.out.println("按类型排序:>>>>>00"+its);
return its;
}
return null;
}
java List<Item> its=new ArrayList<Item>(); Map按value中的某字段排序的更多相关文章
- java的list集合如何根据对象中的某个字段排序?
转自:http://blog.csdn.net/wangjuan_01/article/details/51351633 List集合按某个字段排序 package wjtest_01; import ...
- java中对List<Map<String,Object>>中的中文汉字排序
import java.text.Collator;import java.util.ArrayList;import java.util.Collections;import java.util.C ...
- 根据map中某一字段排序
以上是从小到大的排序...要注意.! 需要jdk8...
- 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30
RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...
- Java集合:List、Set和Map的区别,ArrayList和LinkedList有何区别..........
一.数组和集合的区别: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型): 集合可以存储和操作数目不固定的一组数据. 所有的JAVA集合都位于 java.util包中! J ...
- 词典的实现(3)--使用JAVA类库ArrayList实现Map数据结构
1,在词典的实现(2)-借助顺序表(数组)实现词典文章中使用了自定义的数组代替ArrayList,并实现了Map数据结构的基本功能.而借助JAVA类库ArrayList类的一些方法可以更加容易地实现M ...
- Java中关于 ArrayList 和 Map 的常用遍历方法 (学习笔记,便于以后查询)
一.学习ArrayList与Map时,关于常用遍历方法的记录如下: 二.附源码如下: package com.study.in.myself; import java.util.ArrayList; ...
- Java容器解析系列(4) ArrayList Vector Stack 详解
ArrayList 这里关于ArrayList本来都读了一遍源码,并且写了一些了,突然在原来的笔记里面发现了收藏的有相关博客,大致看了一下,这些就是我要写的(╹▽╹),而且估计我还写不到博主的水平,这 ...
- java集合的实现细节--ArrayList和LinkedList
ArrayList和LinkedList的实现差异 List代表一种线性表的数据结构,ArrayList则是一种顺序存储的线性表,ArrayList底层采用动态数组的形式保存每一个集合元素,Link ...
随机推荐
- windows pip安装 更新
升级: http://blog.csdn.net/liuchunming033/article/details/39578019 pip坏了如何重新安装: https://github.com/pyp ...
- H5移动前端开发常用高能css3汇总
1.禁止a标签点击高亮,这些都是非官方属性,但实用性超强 html,body{ -webkit-touch-callout: none; //禁止或显示系统默认菜单 -webkit-user-sele ...
- Leetcode jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- chrome控制台调试学习笔记 暂未整理
15:03 2015/12/7chrome控制台调试学习:推荐博客:http://www.cnblogs.com/Wayou/p/chrome-console-tips-and-tricks.html ...
- linux install Theano+Tensorflow+Keras
安装过程中,网络状态一定要好,如果安装过程中出现time out的提示信息,今天就可以洗洗睡啦,等明天网络状态好的时候再安装. 安装过程出现不知名的错误的时候,执行第一步,update一下 1.#up ...
- php 执行程序分析
记录程序运行细节 记录程序运行时间 <?php $start = microtime(true); //index.php $end = microtime(true); $time = num ...
- arcmap配置的mxd慢的问题
http://www.360doc.com/content/13/0220/09/3046928_266688511.shtml
- this用法(ryf)
this是javascript语言的一个关键字 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用,比如: function test(){ this.x = 1; } 随着函数使用场合的不 ...
- RAC初体验
什么是RAC? 几乎每一篇介绍RAC的文章开头都是这么一个问题.我这篇文章是写给新手(包括我自己)看的,所以这个问题更是无法忽视. 简单的说,RAC就是一个第三方库,他可以大大简化你的代码过程. 官方 ...
- servlet配置restful
所需jar包如下,jar下载地址如下http://download.csdn.net/detail/zhouminglan1992/9730354 1.web.xml配置 <!--给servle ...