Posted on 2006-11-05 17:50
苑 阅读(176)
评论(0) 编辑 收藏 所属分类:
java基础学习系列
import
java.util.ArrayList;
import
java.util.Iterator;
import
java.util.ListIterator;
public class
MainClass
{
public static
void
main
(
String args
[]) {
ArrayList<String> al =
new
ArrayList<String>
()
;
al.add
(
"C"
)
;
al.add
(
"A"
)
;
al.add
(
"E"
)
;
al.add
(
"B"
)
;
al.add
(
"D"
)
;
al.add
(
"F"
)
;
System.out.print
(
"Original contents of al: "
)
;
Iterator<String> itr = al.iterator
()
;
while
(
itr.hasNext
()) {
String element = itr.next
()
;
System.out.print
(
element +
" "
)
;
}
System.out.println
()
;
ListIterator<String> litr = al.listIterator
()
;
while
(
litr.hasNext
()) {
String element = litr.next
()
;
litr.set
(
element +
"+"
)
;
}
// Now, display the list backwards.
System.out.print
(
"Modified list backwards: "
)
;
while
(
litr.hasPrevious
()) {
String element = litr.previous
()
;
System.out.print
(
element +
" "
)
;
}
}