日期:2014-05-20 浏览次数:20810 次
import java.util.ArrayList;
import java.util.Iterator;
public class IteratorTest {
public static void main(String[] args)
{
ArrayList<String> str = new ArrayList();
for (int i = 0; i <=20; i++)
{
str.add("String" + i);
}
for (String myStr : str)
{
System.out.println(myStr);
}
for (Iterator i = str.iterator(); i.hasNext();)
{
System.out.println(i.next());
}
}
}
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
public class IteratorTest
{
public IteratorTest()
{
}
public static void main(String args[])
{
ArrayList str = new ArrayList();
for(int i = 0; i <= 20; i++)
{
str.add((new StringBuilder()).append("String").append(i).toString());
}
String myStr;
for(Iterator i$ = str.iterator(); i$.hasNext(); System.out.println(myStr))
{
myStr = (String)i$.next();
}
for(Iterator i = str.iterator(); i.hasNext(); System.out.println(i.next())) { }
}
}