Iterable
Iterable是一个泛型接口 。可以通过for-each循环,从Iterable获取Iterator或者通过Iterable的for each()方法。
import java.util.ArrayList;
/**
* Created with Intellij JDEA
* Description:通过for-each循环
* User:
* Date:2022-03-14
* Time:13:00
*/
public class TestDemo {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
list.add("Hello");
list.add("world");
list.add("beijing");
for(String element:list){
System.out.println(element.toString());
}
}
}
import java.util.ArrayList;
import java.util.Iterator;
/**
* Created with Intellij JDEA
* Description:从Iterable获取iterator
* User:
* Date:2022-03-14
* Time:13:00
*/
public class TestDemo {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
l