java entry
我希望要一个ArrayList<Entry>,类似C++中的pair,
可是Map.Entry是个接口,不能实例化,能够像以下这样写
HashMap<Integer, Integer> G = new HashMap<Integer,Integer>();
G.put(1, 9); G.put(4, 6); G.put(2, 8);G.put(3, 7);
ArrayList<Map.Entry<Integer, Integer>> arrayList = new
ArrayList<Map.Entry<Integer, Integer>(G.entrySet());
ArrayList<Map.Entry<Integer, Integer>> arrayList = new
ArrayList<Map.Entry<Integer, Integer>>();
arrayList.add(new AbstractMap.SimpleEntry(1, 9));
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("d", 2);
map.put("c", 1);
map.put("b", 1);
map.put("a", 3); List<Map.Entry<String, Integer>> infoIds =
new ArrayList<Map.Entry<String, Integer>>(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<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> 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<Map.Entry<String,Double>> termls = new ArrayList<Map.Entry<String,Double>>();
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<Map.Entry<String, Double>>(){
public int compare(Map.Entry<String, Double> o1,Map.Entry<String, Double> 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();
java entry的更多相关文章
- Java Entry使用
参考: http://blog.csdn.net/sunmenggmail/article/details/8952712 http://www.cnblogs.com/fstang/archive/ ...
- java引用类型简述
主要内容: 1.引用类型简述 2.对象的可达性 3.软引用的垃圾回收分析 4.WeakHashMap分析 5.ThreadLocal内存泄漏分析 1.引用类型简述 在Java语言中除了基本数据类型外, ...
- 怎样学好 java ?
浅谈Java的学习之路--怎样学好JAVA ?Java - 近10年来计算机软件发展过程中的传奇,其在众多开发者心中的地位就如"屠龙刀"."倚天剑". Java ...
- The main concepts
The MVC application model A Play application follows the MVC architectural pattern applied to the we ...
- Spring学习总结四——SpringIOC容器四
一:spring容器给bean对象注入属性值 1:注入基本属性值 a. 创建MessageBean类: /** * */ package com.hlcui.dao; /** * @author Ad ...
- 05-spring-bean注入
spring中只有两大核心技术: 控制反转(IOC)&依赖注入(DI),AOP(面向切面编程) 依赖注入:指利用配置文件的关系,来决定类之间的引用关系,以及数据的设置操作. 构造方法注入 默认 ...
- 【Spring实战】—— 7 复杂集合类型的注入
之前讲解了Spring的基本类型和bean引用的注入,接下来学习一下复杂集合类型的注入,例如:List.Set.Map等. 对于程序员来说,掌握多种语言是基本的技能. 我们这里做了一个小例子,程序员们 ...
- Android10_原理机制系列_Binder机制
前言 Binder 从java到c++到kernel,涉及的内容很多,很难在一篇文章中说清楚.这篇主要是自我记录,方便后续查询并拆分总结的. 因为涉及的的确非常多,不能面面俱到,所以可能一些地方感觉比 ...
- 为了搞清楚类加载,竟然手撸JVM!
作者:小傅哥 博客:https://bugstack.cn Github:https://github.com/fuzhengwei/CodeGuide/wiki 沉淀.分享.成长,让自己和他人都能有 ...
随机推荐
- VMware Workstation 9.0 安装苹果Mac OS X10.9系统
摘自:http://www.wuwenhui.cn/3133.html 一.安装所需要的软件: 1.VMware Workstation 9.0 点击下载 2.unlock-all-v110.zip ...
- Jquery学习笔记:获取jquery对象的基本方法
jquery最大的好处是将js对html页面的操作(读写)进行了封装,隔离了浏览器的差异性,并简化了操作,和提供了强大的功能. 在web页面中,所有的js操作都是围绕操作dom对象来的.而jquery ...
- MUI跳转页面传值
1.打开新的页面.通过 mui.openWindow 打开页面extras参数传递参数 mui.openWindow({ id: "yingshou-" + newid, url: ...
- [置顶] 正则表达式应用:匹配email地址
email的组成主要有三部分 1用户名部分 2@ 3域名部分 1用户名部分 用户名一般有数值字母下划线组成,所以正则表达式为:[\da- ...
- Boost 库Program Options--第二篇
程式執行參數處理函式庫:Boost Program Options(2/N) 前一篇已經大致解釋了 Boost Program Options 基本上的使用方法.而這一篇,則來細講一下選項描述(opt ...
- kiddouk/redisco
kiddouk/redisco A Python Library for Simple Models and Containers Persisted in Redis
- CairoSVG - Convert SVG to PNG or PDF - Contents
CairoSVG - Convert SVG to PNG or PDF - Contents User Documentation Author Guillaume Ayoub Date 2011- ...
- 在uboot里面加入环境变量使用run来运行
Author:杨正 Date:2014.11.11 Email:yz2012ww@gmail.com QQ:1209758756 在移植uboot的时候,能够在uboot里面加入定义一些自己的环 ...
- POJ 3301 Texas Trip
题目大意: 在二维坐标系中给出一些点.求能覆盖他们的最小正方形的面积(正方形的边不一定平行坐标轴) 解题思路: 对于一个点.若坐标轴旋转a度(弧度制).那么X'=X*cos(a)-Y*sin(a);Y ...
- 异常:未能载入文件或程序集”DAL”或它的某一个依赖项——解决的方法
以下是我再使用抽象工厂+反射重构机房时,在Factoy中出现了以下一个问题: 去网上查了一下资料,发现这是一个非常普遍的问题,它出现的原因主要有两种: 第一种: 载入DLL路径错误.解决的方法是调整D ...