/** * 使用 for增强对 Map遍历 */ package com.wl.entry; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class Demo { public static void main(String[] args) { Student student1=new Student(100,"小明"); Student student2=new Student(101,"张三"); Student student3=new Student(102,"李四"); Map<Integer,Student> stus=new HashMap<Integer, Student>(); stus.put(student1.getId(), student1); stus.put(student2.getId(), student2); stus.put(student3.getId(), student3); /** * 使用 for增强对 Map遍历 */ for(Entry<Integer,Student> stu:stus.entrySet()){ System.out.println(stu.getKey()+","+stu.getValue().getName()); } } } class Student{ private int id; private String name; public Student() { // TODO Auto-generated constructor stub } public Student(int id,String name) { this.id=id; this.name=name; } public int getId() { return id; } public String getName() { return name; } public void setId(int id) { this.id = id; } public void setName(String name) { this.name = name; } }
相关推荐
java Map 遍历方法 Map map = new HashMap(); Iterator it = map.entrySet().iterator(); while (it.hasNext()) {
主要提供java中的map的遍历实例及效率比较
java,利用keySet进行遍历map
map遍历的三种方法map遍历的三种方法map遍历的三种方法
java中常用的Map的两种遍历方法...
java集合中map的三种遍历有详细的代码。
主要介绍了JAVA8独有的map遍历方式(非常好用),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
vue中循环遍历使用的指令是v-for 1.v-for遍历数组 (1)value in arr 遍历数组中的元素 (2)(value,index) in arr 遍历数组中的元素和数组下标 运行代码: <body> <li v-for=value>{{value}}</li><br> ...
主要介绍了java遍历Map的几种方法,结合实例形式分析了使用循环与迭代等方法操作Map遍历的相关技巧,需要的朋友可以参考下
这是一人篇关于JAVA MAP遍历的讲解的文章,希望对你有用
Map的遍历大体有3种: 1、遍历Map.entrySet():它的每一个元素都是Map.Entry对象,这个对象中, 放着的就是Map中的某一对key-value; 2、遍历Map.keySet():它是Map中key值的集合,我们可以通过遍历这个集合来 ...
详细介绍啦遍历map的几种方式,好吧,共有四种方式
自己整理的map遍历的方式及性能分析,欢迎批评指正哈哈
JAVA遍历Map所有元素.docaaaaaaaaaaa
你知道map的遍历方法有几种吗? 那这几种的区别是什么呢? 那种更简单、高效呢? 我的资源文件将告诉你。
Java.Map的三种遍历方法
Map 遍历: Map, String> map = new HashMap, String>(); map.put(1, "a"); map.put(2, "b"); map.put(3, "ab"); map.put(4, "ab"); map.put(4, "ab");// 和上面相同 , 会自己筛选 System.out.println(map.size());
for循环中的map遍历没走的原因-原代码
C++11 unordered_map与map(插入,遍历,Find)效率对比。
JAVA中map集合遍历的五种方法,简单易学,java开发入门的基础知识!