package com.yuwanlong.hashing;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; /**
* @author Yu Wanlong
*/ public class ValidAnagram {
public static void main(String[] args) {
Map<String, Double> map = new HashMap();
map.put("1", 8.);
map.put("2", 12.);
map.put("3", 53.);
map.put("4", 33.);
map.put("5", 11.);
map.put("6", 3.);
map.put("7", 3.);
map.put("8", 1.);
//List<Entry<String,Integer>> list = new ArrayList(map.entrySet());
//Collections.sort(list, (o1, o2) -> (o1.getValue() - o2.getValue()));
String minKey = getMapMinOrMaxValueKey(map, "min");
String maxKey = getMapMinOrMaxValueKey(map, "max");
System.out.println(map.get(minKey));
System.out.println(map.get(maxKey));
} public static String getMapMinOrMaxValueKey(Map<String, Double> map, String choose) {
List<Entry<String,Double>> list = new ArrayList(map.entrySet());
Collections.sort(list, (o1, o2) -> (o1.getValue().intValue() - o2.getValue().intValue()));
String key = "";
if (choose.equals("min")) {
key = list.get(0).getKey();
} else if (choose.equals("max")) {
key = list.get(list.size() - 1).getKey();
}
return key;
}
}

最新文章

  1. 我的EF功能
  2. 腾讯AlloyTeam移动Web裁剪组件AlloyCrop正式开源
  3. perl 从文件里读出变量无法使用解决办法
  4. 供应商和管理员查看供应商地址簿信息SQL
  5. The file couldn’t be opened because you don’t have permission to view it
  6. 502 Bad Gateway nginx 解决
  7. Js跳出循环
  8. oracle的存储过程语法(转)
  9. Sublime中开发Ruby
  10. 自定义checkbox, radio样式
  11. 数据保存策略(Retention Policies)
  12. 斐讯K1 K2 开启Telnet
  13. 日志那点事儿——slf4j源码剖析
  14. 通过数组和枚举简化GPIO操作编码(转)
  15. 如何利用好github的问题
  16. 线性查找算法(BFPRT)
  17. PHP的数据加密解密
  18. mes平台Action类模版
  19. 【Unity】6.4 Transform--移动、旋转和缩放游戏对象
  20. 一个 图片 滚动 飞入的css特效

热门文章

  1. rpm yum 等命令无响应的解决方法
  2. leetcode897
  3. Unity3D Physics Keynote
  4. Unity抗锯齿的设置
  5. SQLServer中的事物与锁
  6. Android中dp、dpi与px的关系
  7. 720. Longest Word in Dictionary 能连续拼接出来的最长单词
  8. Hyperledger Chaincode启动过程
  9. 认识Session
  10. 网页中的foot底部定位问题