mapent
package test12; import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set; public class Entre_Demo {
public static void main(String ... args){
mapEntre(); }
public static void mapEntre(){
Map<String,Integer> map=new HashMap<>();
map.put("tom",);
map.put("ok",);
Set<Map.Entry<String,Integer>> mapen=map.entrySet();//泛型内嵌套泛型。获得是Set集合。
Iterator<Map.Entry<String,Integer>> mapit=mapen.iterator();
while (mapit.hasNext()){
Map.Entry<String,Integer> mape=mapit.next();
// String mapkey=mapit.next().getKey();
String mapkey=mape.getKey();//获取键值
Integer mapval=mape.getValue();//获得val。
// Integer mapval=mapit.next().getValue();
System.out.print(mapkey+"-------------------"+mapval);
}
}
}
Map的方法中entrySet()返回是Set集合,集合内的对象类型为:Map.Entry<k,v>类型,属于泛型中嵌套另一个类型。
Set<Map.Entry<K,V>> entrySet()
Interface Map.Entry<K,V> 提供的方法。entrySet()是返回的是这个接口实现类的对象。
看下方法:
V setValue(V value) 设置新的value值。
mapent的更多相关文章
- java 集合(五)MapDemo
package cn.sasa.demo3; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedH ...
随机推荐
- SQL0286N 找不到页大小至少为 "8192"、许可使用授权标识 "db2inst" 的缺省表空间。
在 SQL 处理期间,它返回: SQL0286N 找不到页大小至少为 "8192".许可使用授权标识 "db2inst" 的缺省表空间. 顾名思义,DB2默认 ...
- HDU2181(KB2-C)
哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- vscode 代码跳转之PHP篇
1.安装插件:PHP IntelliSense 2.配置:"php.executablePath": "C:\\php\\php.exe", 但是目前有问题,跨 ...
- 纯css修改复选框默认样式
input[type='checkbox']{ width: 20px; height: 20px; background-color: #fff; -webkit-appearance:none; ...
- flutter圆角效果的实现
new Material( borderRadius: BorderRadius.circular(20.0), shadowColor: Colors.blue.shade200, elevatio ...
- leetCode题解 Reverse Words in a String III
1.题目描述 Given a string, you need to reverse the order of characters in each word within a sentence wh ...
- leetCode题解之寻找一个数在有序数组中的范围Search for a Range
1.问题描述 Given an array of integers sorted in ascending order, find the starting and ending position o ...
- leetCode题解之反转字符串中的元音字母
1.问题描述 Reverse Vowels of a String Write a function that takes a string as input and reverse only the ...
- [转载]Cool, Tomcat is able to handle more than 13,000 concurrent connections
Last time I have promised you to take a look at more real life scenario regarding threads. In the la ...
- Oracle EBS 计划请求
SELECT fcp.concurrent_program_name, decode(fcre.description, NULL, fcpt.user_concurrent_program_name ...