List有三種循環(huán)方式:
分別是經(jīng)典的for循環(huán),迭代器(list.iterator()),foreache循環(huán)(和C#相同哦)
測試代碼如下:
public static void main(String[] args) { |
List<String> list= new ArrayList<String>(); |
System.out.println( "------經(jīng)典的for循環(huán)-----" ); |
for ( int i = 0 ; i < list.size(); i++) { |
System.out.println(list.get(i)); |
System.out.println( "-------Iterate循環(huán)--------" ); |
Iterator<String> iter=list.iterator(); |
System.out.println(iter.next()); |
System.out.println( "-------foreach循環(huán)---------" ); |
for (String string : list) { |
System.out.println(string); |
|