zoukankan      html  css  js  c++  java
  • hashMap分别获取所有key和value

    import java.util.*;
     
    public class Main {
        public static void main(String[] args){
    //        Scanner scanner=new Scanner(System.in);//在线笔试
            HashMap<Integer,Integer> map=new HashMap<Integer, Integer>();
            map.put(1,2);
            map.put(2,3);
            map.put(3,4);
            map.put(4,4);
     
     
            //获取所有key
            Set<Integer> keys=map.keySet();
            Iterator<Integer> iterator1=keys.iterator();
            while (iterator1.hasNext()){
                System.out.print(iterator1.next() +", ");
            }
            System.out.println();
            System.out.println("------------------------");
     
            //获取所有value
            Collection<Integer> values=map.values();
            Iterator<Integer> iterator2=values.iterator();
            while (iterator2.hasNext()){
                System.out.print(iterator2.next()+", ");
            }
            System.out.println();
            System.out.println("------------------------");
     
            //去除value中重复值,相同值仅仅保留一个
            Set<Integer> valuesSimple=new HashSet<Integer>();
            for(int i:values){
                valuesSimple.add(i);
            }
            Iterator<Integer> iterator3=valuesSimple.iterator();
            while (iterator3.hasNext()){
                System.out.print(iterator3.next()+", ");
            }
        }
    }
    
    
    https://blog.csdn.net/caoxiaohong1005/article/details/78211825
  • 相关阅读:
    Cufon css3@font-face
    HTML5 Canvas
    HTML5 Canvas 的宽高
    :nth-child()
    new Image()
    ios有些机型input和fixed导致的页面错位问题
    使用performance进行前端性能监控
    throttle(节流)和debounce(防抖)
    object-fit/object-position
    flex布局与ellipsis冲突问题
  • 原文地址:https://www.cnblogs.com/isme-zjh/p/12809611.html
Copyright © 2011-2022 走看看