博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java entry
阅读量:7287 次
发布时间:2019-06-30

本文共 1772 字,大约阅读时间需要 5 分钟。

我希望要一个ArrayList<Entry>,类似C++中的pair,

可是Map.Entry是个接口,不能实例化,能够像以下这样写

HashMap
G = new HashMap
();G.put(1, 9); G.put(4, 6); G.put(2, 8);G.put(3, 7); ArrayList
> arrayList = new ArrayList
(G.entrySet());

ArrayList
> arrayList = new ArrayList
>();arrayList.add(new AbstractMap.SimpleEntry(1, 9));

Map
map = new HashMap
();map.put("d", 2);map.put("c", 1);map.put("b", 1);map.put("a", 3);List
> infoIds = new ArrayList
>(map.entrySet());//排序前for (int i = 0; i < infoIds.size(); i++) { String id = infoIds.get(i).toString(); System.out.println(id);}//d 2//c 1//b 1//a 3//排序Collections.sort(infoIds, new Comparator
>() { public int compare(Map.Entry
o1, Map.Entry
o2) { //return (o2.getValue() - o1.getValue()); return (o1.getKey()).toString().compareTo(o2.getKey()); }}); //排序后for (int i = 0; i < infoIds.size(); i++) { String id = infoIds.get(i).toString(); System.out.println(id);}//依据key排序//a 3//b 1//c 1//d 2//依据value排序//a 3//d 2//b 1//c 1

List
> termls = new ArrayList
>(); for(String s: tf.get(i).keySet()) { termls.add(new AbstractMap.SimpleEntry(s, tf.get(i).get(s)*1.0*Math.log10(count*1.0/df.get(s)))); } Collections.sort(termls, new Comparator
>(){ public int compare(Map.Entry
o1,Map.Entry
o2){ return(o2.getValue().compareTo(o1.getValue())); } } ); System.out.println("line " + (i+1)); for (int ind = 0; ind < termls.size(); ++ind){ System.out.print(termls.get(ind).toString()+" "); } System.out.println();

转载地址:http://wipjm.baihongyu.com/

你可能感兴趣的文章
FreeBSD与Linux的比较
查看>>
redis配置文件全解及常用命令
查看>>
Zabbix汇总分组流量
查看>>
BootStrap之基础-1 BootStrap起步(基本概念、环境搭建)
查看>>
linux自学笔记--bash特性
查看>>
Linux平台中设置文件的执行、写权限
查看>>
CentOS7-虚拟网卡的删除
查看>>
Ruby中的include和extend
查看>>
Sencha的Eclipse插件提示和技巧
查看>>
超全前端面试题及答案
查看>>
使用纯真版IP地址库,根据IP判断所在地
查看>>
转:SQL注入攻击的原理
查看>>
DATA VISUALIZATION – PART 2
查看>>
如何用几何画板把圆奇数等分
查看>>
数据结构-线性表操作
查看>>
5Python全栈之路系列之算法
查看>>
一个效果不错的Java Swing模拟屏幕截图工具类
查看>>
MySQL 的主从复制
查看>>
把合同中红色印章实现打印不显示方法
查看>>
linux调优工具使用
查看>>