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.               ........  
  • 相关阅读:
    第一次作业
    第五次作业
    第四次作业
    第三次作业
    第二次作业
    第一次作业
    第五次作业
    第四次作业
    第三次作业
    第二次作业
  • 原文地址:https://www.cnblogs.com/gaozedong66/p/6553022.html
Copyright © 2011-2022 走看看