zoukankan      html  css  js  c++  java
  • 对 set 的遍历

    1. 对 set 的遍历  
    2.   
    3. 1.迭代遍历:  
    4. Set<String> set = new HashSet<String>();  
    5. Iterator<String> it = set.iterator();  
    6. while (it.hasNext()) {  
    7.   String str = it.next();  
    8.   System.out.println(str);  
    9. }  
    10.   
    11. 2.for循环遍历:  
    12. for (String str : set) {  
    13.       System.out.println(str);  
    14. }  
    15.   
    16.   
    17. 优点还体现在泛型 假如 set中存放的是Object  
    18.   
    19. Set<Object> set = new HashSet<Object>();  
    20. for循环遍历:  
    21. for (Object obj: set) {  
    22.       if(obj instanceof Integer){  
    23.                 int aa= (Integer)obj;  
    24.              }else if(obj instanceof String){  
    25.                String aa = (String)obj  
    26.              }  
    27.               ........  
  • 相关阅读:
    ICMP协议
    观察者模式-Observer
    模板方法模式-Template Method
    Java的演变过程
    汉诺塔-Hanoi
    外观模式-Facade
    JDK5-增强for循环
    JDK5-可变参数
    动态代理与AOP
    代理模式-Proxy
  • 原文地址:https://www.cnblogs.com/gaozedong66/p/6553022.html
Copyright © 2011-2022 走看看