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());
    
    		}
    
    	}
    }
    

      

      

  • 相关阅读:
    北京Uber优步司机奖励政策(3月3日)
    ubuntu安装phpstorm
    ubuntu安装typora
    PHP定时任务Crontab结合CLI模式详解
    mysql创建用户,并授予权限
    ubuntu下使用crontab定时器
    Ubuntu 查看当前目录使用的总空间大小
    ubuntu安装ruby,安装sass,安装compass
    open_basedir restriction in effect,解决php引入文件权限问题 lnmp
    canvas 画线
  • 原文地址:https://www.cnblogs.com/ylfeiu/p/3599344.html
Copyright © 2011-2022 走看看