package com.lovecoding.day18.iterator01;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class TestIterator {

    @Test
    public void test01(){

        Collection<String> coll = new ArrayList<>();

        coll.add("1");
        coll.add("2");
        coll.add("3");
        coll.add("4");

        //获取迭代器
        Iterator<String> iterator = coll.iterator();
        //遍历
        while ( iterator.hasNext() ){
            //获取元素
            String next = iterator.next();
            System.out.println(next);
        }

    }
}
