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 沉淀.分享.成长,让自己和他人都能有 ...
随机推荐
- arm:c语言和汇编混合编程
仅作演示. 1.C和汇编可相互调用,汇编子函数格式参考 汇编:普通的函数调用的汇编代码解析 http://www.cnblogs.com/mylinux/p/4139972.html 本文演示了 : ...
- C# 课堂总结1-二进制转换
一.目的:便于计算机表示,稳定性好,符合逻辑运算,真为1,假为0. 二.各进制表示方法: 2进制:0,1 8进制:0-7 16进制:0-9,A,B,C,D,E,F 二.转换方法: 1.各进制转换为10 ...
- AdbWinApi编译详解(本人亲历)
1. 从微软官方下载WDDK,比如:GRMWDK_EN_7600_1.ISO(http://download.microsoft.com/download/4/A/2/4A25C7D5-EFBE-41 ...
- Qt核心剖析: 寻找 QObject 的源代码
本来打算把<Qt学习之路>作为一个类似教程的东西,所以就不打算把一些关系到源代码的内容放在那个系列之中啦.因此今天就先来看一个新的开始吧!这个系列估计不会进展很快,因为最近公司里面要做 f ...
- silentScroll() 滚屏
jQuery.mobile.silentScroll( yPos ) 滚动到一个特定的Y坐标位置,没有触发涡旋的事件监听器 yPos:Y坐标.类型:数字.默认值: //滚屏到y 100px处 $.mo ...
- LifecyclePhaseNotFoundException(转)
This error is generated if you try to invoke a build command that Maven does not understand. In gene ...
- vim添加删除多行注释
CTRL+V进入可视化模式 移动光标上移或者下移,选中多行的开头 选择完毕后,按大写的的I键,此时下方会提示进入“insert”模式,输入你要插入的注释符 最后按ESC键,你就会发现多行代码已经被注释 ...
- [Windows Phone]常用类库&API推荐
原文 [Windows Phone]常用类库&API推荐 简介: 把自己的应用程序搭建在稳定的API之上,这会使得我们在开发时能把精力都集中在程序的业务逻辑之上,避免重复造轮子,并且使得程序结 ...
- 【图像处理】Gabor过滤器
Gabor内核参考wiki 使用实数Real的公式计算核函数代码: Mat getGaborFilter(float lambda, float theta, float sigma2,float g ...
- openfire数据库中文乱码问题
1.首先数据库的编码设置为UTF-8 2.项目的编码也要设置为UTF-8 假设数据保存到数据库的时候还有乱码 就要改动openfire配置文件 在openfire主文件夹\conf\openfire ...