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());
            }
    
        }
  • 相关阅读:
    Path Sum
    Binary Tree Level Order Traversal II
    Jump Game
    leedcode 刷题-V2
    (2016 年) githup 博客地址 : https://github.com/JMWY/MyBlog
    算法分类总结
    剑指 Offer 题目汇总索引
    LeedCde 题解目录
    趣味算法总目录
    常用
  • 原文地址:https://www.cnblogs.com/luzhanshi/p/13061256.html
Copyright © 2011-2022 走看看