java Iterator双向迭代输出
1 package test;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.ListIterator;
6 import java.util.SortedSet;
7 import java.util.TreeSet;
8
9 public class test {
10 public static void main(String[] args) {
11 List<String> all=new ArrayList<String>();
12 all.add("hello");
13 all.add("_");
14 all.add("World");
15 ListIterator<String> iter=all.listIterator();
16 while(iter.hasNext()){
17 System.out.print(iter.next());
18 }
19 while(iter.hasPrevious()){
20 System.out.print(iter.previous());
21 }
22 }
23 }