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 沉淀.分享.成长,让自己和他人都能有 ...
随机推荐
- C# 点击窗口任意位置拖动
代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; ...
- SGU 415. Necessary Coins ( 背包dp )
题意大概是:给出N个硬币, 面值为a_i, 问要凑成X元哪些硬币是不可或缺的.1 ≤ N ≤ 200, 1 ≤ x ≤ 10^4 直接枚举, 然后就是01背包了. 为了不让复杂度多乘个N, 我们就从左 ...
- java io学习记录(路径分隔符)
java路径分隔符(路径表示) path="E:\\xp\\test\\2.jpg"; path="E:/xp/test/2.jpg"; path=" ...
- Windows Phone 8初学者开发—第20部分:录制Wav音频文件
原文 Windows Phone 8初学者开发—第20部分:录制Wav音频文件 原文地址:http://channel9.msdn.com/Series/Windows-Phone-8-Develop ...
- [教程]安装青鸟云Web服务器
青鸟云Web服务器 支持的安装环境: Windows XP (32bit) Windows Server 2003/R2 (32bit) Windows 7 (32/64bit) Windows Se ...
- 解决基于BAE python+bottle开发上的一系列问题 - artwebs - 博客频道 - CSDN.NET
解决基于BAE python+bottle开发上的一系列问题 - artwebs - 博客频道 - CSDN.NET 解决基于BAE python+bottle开发上的一系列问题 分类: python ...
- Light OJ 1318 Strange Game 组合数+高速幂+分解因子
长度为l的用k种字符组成的字符串有k^l中 当中m个字符要不同样 那就是k^l*C(l, m)*(k-1)^m 有反复 要除以2 可是你mod n了 不能直接除 n不一定是素数 所以不能乘以逆元 所以 ...
- NHibernate -- HQL
使用NHibernate中的HQL来查询数据. 代码: /// <summary> /// 查找事件 /// </summary> private void btn_Selec ...
- Genymotion 插件在 Eclipse 和 Android Studio 中点击后无法初始化 Initialize Engine: failed 解决方法
Genymotion 插件已更新至 1.0.6,目前无法初始化的问题已经解决. ------------------------------------------------------------ ...
- dump json 显示中文问题
[root@dr-mysql01 ~]# cat a2.pl my $url="http://192.168.32.101:3000/api/getcode?env=zj&phone ...