package package4;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class ListIteratorDemo {
public static void main(String[] args) {
//创建集合
List<String> list =new ArrayList<>();
//添加元素
list.add("hello");
list.add("world");
list.add("java");
//通过List集合的listIterator()方法得到
ListIterator lit =list.listIterator();
while(lit.hasNext()){
String s = (String) lit.next();
System.out.println(s);
}
System.out.println("-------------");
while(lit.hasPrevious()){
String b = (String) lit.previous();
System.out.println(b);
}
while(lit.hasNext()){
String s = (String) lit.next();
if(s.equals("world")){
lit.add("javase");
}
}
System.out.println(list);
}
}
//运行结果
hello
world
java
-------------
java
world
hello
[hello, world, javase, java]
标签:java,String,迭代,list,System,列表,lit,world
From: https://www.cnblogs.com/knlf/p/16794205.html