package ArrayList; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Arraya { public static void main(String[] args) { // TODO 自动生成的方法存根 List<String> list =new ArrayList<String>(); System.out.println("100元素:"); for(int i=0;i<100;i++) { list.add(""+i); } System.out.println("输出字符:"); Iterator it = list.iterator(); while(it.hasNext()) { Object obj = it.next(); System.out.println(obj); } System.out.println("字符串长度:"+list.size()); System.out.println("获取元素:"); try { System.out.println("第50元素: "+list.get(50)); System.out.println("第102元素:"); System.out.println(list.get(102)); }catch(Exception e){ System.out.println("元素下标越界!"); } System.out.println("字符串长度"+list.size()); } }