zoukankan      html  css  js  c++  java
  • 集合

    1.主要掌握5个接口:

    Collection List Set Map Iterator Enumeration

    2.不允许重复的子接口:Set

    3.Set中常用的两个子类:散列存放的子类:HashSet

      顺序存放的子类TreeSet

    4. Map接口

    public Set<K> keySet() ,将Map中的所有key以Set集合的方式返回

    public Set<Map.Entry><K,V>>entrySet(),将Map集合变为Set集合

    Map的输出

    package com.ylfeiu.utils;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    
    public class HashMapEcho {
    	public static void main(String[] args) {
    		Map<Integer, String> map = new HashMap<>();
    		map.put(1, "hello");
    		map.put(2, "txt");
    		map.put(2, "txt2");
    		map.put(null, "ylfeiu");
    		map.put(1, "hello");
    
    		Set<Integer> set = map.keySet();
    		Iterator<Integer> car = set.iterator();
    
    		while (car.hasNext()) {
    			Integer key = car.next();
    			System.err.println(key + "------------>" + map.get(key));
    		}
    
    	}
    }
    

      

    例子2
    
    package com.ylfeiu.utils;
    
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Set;
    
    public class HashMapEcho2 {
    	public static void main(String[] args) {
    		Map<Integer, String> map = new Hashtable<>();
    		map.put(1, "hello");
    		map.put(2, "txt");
    		map.put(2, "txt2");
    		// map.put(null, "ylfeiu");//HashTable不能使用null做key
    		map.put(1, "hello");
    
    		Set<Map.Entry<Integer, String>> set = map.entrySet();//把Map.Entry当作一个对象
    		Iterator<Map.Entry<Integer, String>> car = set.iterator();
    
    		while (car.hasNext()) {
    			Map.Entry<Integer, String> me = car.next();
    			System.err.println(me.getKey() + "------------>" + me.getValue());
    
    		}
    
    	}
    }
    

      

      

  • 相关阅读:
    九宫格拼图 支持44 55等
    js 怎样获取div 图片等的宽度,只要值,不要px
    spring boot单元测试之RestTemplate(一)
    java设计模式-原型(prototype)
    Hibernate注解(二):关联关系映射注解
    spring之@value详解二(转载)
    spring之@Value详解(转载)
    Spring之基于注解的注入
    Spring之bean生命始末
    Spring之bean后处理器
  • 原文地址:https://www.cnblogs.com/ylfeiu/p/3599344.html
Copyright © 2011-2022 走看看