Map 根据value 获取key
来源:互联网 发布:手机电话录音软件 编辑:程序博客网 时间:2024/05/01 00:57
package com.basic.object;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class GetKeyByValue {
public static ArrayList getAllKey(Map<Object, Object> sourceMap, Map<String, Object> temp){
ArrayList list = new ArrayList();
for (Object getKey : sourceMap.keySet()) {
if (temp.equals(sourceMap.get(getKey))){
list.add(getKey);
System.out.println("Adding the key...");
}
//System.out.println("Can not add the key...");
}
return list;
}
public static void main(String[] args) {
Map<Object, Object> sourceMap = new HashMap<Object, Object>();
Map<String, Object> temp = new HashMap<String, Object>();
temp.put("shanghai", "CN");
temp.put("shenzhen", "CN");
sourceMap.put("P", temp);
ArrayList list = getAllKey(sourceMap, temp);
System.out.println("Run here...");
for (int i=0; i<list.size(); i++){
System.out.println("The key is ...." + list.get(i));
}
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class GetKeyByValue {
public static ArrayList getAllKey(Map<Object, Object> sourceMap, Map<String, Object> temp){
ArrayList list = new ArrayList();
for (Object getKey : sourceMap.keySet()) {
if (temp.equals(sourceMap.get(getKey))){
list.add(getKey);
System.out.println("Adding the key...");
}
//System.out.println("Can not add the key...");
}
return list;
}
public static void main(String[] args) {
Map<Object, Object> sourceMap = new HashMap<Object, Object>();
Map<String, Object> temp = new HashMap<String, Object>();
temp.put("shanghai", "CN");
temp.put("shenzhen", "CN");
sourceMap.put("P", temp);
ArrayList list = getAllKey(sourceMap, temp);
System.out.println("Run here...");
for (int i=0; i<list.size(); i++){
System.out.println("The key is ...." + list.get(i));
}
}
}
0 0
- Map 根据value 获取key
- 在map中根据value获取key
- HashMap 根据Value获取Key
- HashMap根据value获取key
- Map通过key获取value
- Map循环获取key+value
- Map排序,获取map的第一值,根据value取key等操作(数据预处理)
- map根据value得到key值
- java Map根据value得到key值
- C++ map 根据value找key
- java根据map指定的value值获取对应的key值使用Gson实现
- 关于HashMap根据Value获取Key
- (转)关于HashMap根据Value获取Key
- java Map遍历获取key,value值
- 获取map的key和value
- C++ map通过key获取value
- Java Map获取key和value
- 获取map的key和value
- vi 快捷键积累
- 选择问题算法
- c语言读写文件fopen和fopen
- setlocale
- Gauss-Laguerre quadrature rule
- Map 根据value 获取key
- Redis:Redis的介绍与安装部署
- Redis:数据类型
- POJ2187【旋转卡壳】
- Error in an XML file: aborting build 错误提示的解决办法
- LeetCode - Sudoku Solver
- java中插件机制和热升级的实现方案
- Mybatis入门实例(二)——添加ehcache缓存支持
- Search in Rotated Sorted Array II