zoukankan      html  css  js  c++  java
  • 27.集合1------Collection

    1.学习目录

     2.集合类体系结构

     

     

     3.Collection概述

     4.Collection方法

     5.Collection的遍历(Iterator)

        public static void main(String[] args) {
            Collection<String> collection = new ArrayList<String>();
            collection.add("hello");
            collection.add("world");
            Iterator<String> iterator = collection.iterator();
    /**
     *     public Iterator<E> iterator() {
     *         return new Itr();
     *     }
     *
     *     private class Itr implements Iterator<E> {
     * ...
     *          }
     */
            /**
             System.out.println(iterator.next());//hello
             System.out.println(iterator.next());//world
             System.out.println(iterator.next());//Exception in thread "main" java.util.NoSuchElementException
             */
    /*        if (iterator.hasNext()){
                System.out.println(iterator.next());//hello
            }
            if (iterator.hasNext()){
                System.out.println(iterator.next());//hello
            }
            if (iterator.hasNext()){
                System.out.println(iterator.next());//无输出
            }*/
            //用while循环改进
    
            while (iterator.hasNext()) {
                System.out.println(iterator.next());
            }
    
        }
  • 相关阅读:
    02-高阶函数 map filter sorted
    01-切片的赋值操作
    学习资料记录
    django_初级学习(1)
    git配置使用
    openpyxl操作表格(2)
    openpyxl模块操作excell表格(1)
    精简语法
    MySQL常见面试题
    02-图片转字符画
  • 原文地址:https://www.cnblogs.com/luzhanshi/p/13061256.html
Copyright © 2011-2022 走看看