• list,set,map集合的遍历


    package com.test;
    
    import java.awt.List;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    
    /**
     * list集合遍历  set集合遍历  hashmap集合遍历
     * 
     * @author 18430
     *
     */
    
    public class Test {
    	public static void main(String[] args) {
    
    		Student student1 = new Student("zhangsan", 90);
    		Student student2 = new Student("lisi", 78);
    		Student student3 = new Student("wangwu", 56);
    
    		ArrayList<Student> list = new ArrayList<Student>();
    		list.add(student1);
    		list.add(student2);
    		list.add(student3);
    
    		for (int i = 0; i < list.size(); i++) {
    			System.out.print(list.get(i));
    		}
    		System.out.println();
    		System.out.println("for循环遍历list================================================");
    
    		//
    		Iterator iterator = list.iterator();
    		while (iterator.hasNext()) {
    			System.out.print(iterator.next());
    		}
    
    		System.out.println();
    		System.out.println("迭代器遍历list================================================");
    
    		//
    		for (Student student : list) {
    			System.out.print(student);
    		}
    
    		System.out.println();
    		System.out.println("foreach遍历list================================================");
    
    		HashSet<Student> set = new HashSet<>();
    		set.add(student1);
    		set.add(student2);
    		set.add(student3);
    
    		for (Student student : set) {
    			System.out.print(student);
    		}
    
    		System.out.println();
    		System.out.println("foreach遍历set================================================");
    
    		Iterator iterator1 = set.iterator();
    		while (iterator1.hasNext()) {
    			System.out.print(iterator1.next());
    		}
    
    		System.out.println();
    		System.out.println("迭代器遍历set================================================");
    
    		HashMap map = new HashMap();
    		map.put("1", student1);
    		map.put("2", student2);
    		map.put("3", student3);
    
    		Iterator iterator3 = map.keySet().iterator();
    		while (iterator3.hasNext()) {
    			System.out.println(map.get(iterator3.next()));
    		}
    
    		System.out.println();
    		System.out.println("map集合的遍历================================================");
    
    	}
    
    }
    

      

  • 相关阅读:
    (转)S5PV210之UBOOT2011.06启动过程解析
    (转)S5PV2101210启动方式和代码前16字节
    (转)UBoot启动过程详细版的完全分析
    uboot中.lds连接脚本文件的分析
    makefile中的@
    (转)GNU ARM汇编(十七)uboot的makefile和mkconfig解读
    (转)关于uboot中的.balignl 16,0xdeadbeef的理解
    (转)ARM协处理学习
    linux下拷贝的时候有时候会出现cp:omitting directory的错误
    Quartz JobListener 任务监听器
  • 原文地址:https://www.cnblogs.com/yanweichen/p/9281594.html
Copyright © 2020-2023  润新知