public Class Demo{ public static void main(String[] args){ ArrayList<String> al=new ArrayList<>(); List<String> list=al; Connection<String> collect=al; collect.add("Tom"); list,add("Alice"); //这里可以写for循环也可以写foreach或是用迭代 for(intt i=0:i<al.size();i++){ String s=al.get(i); system.out.printIn(s); } for(String s:collect){ System.out.printLn(s); } Iterator<String> it=collect.iterator(); while(it.hashNext()){ String s=it.next(); system.out.printLn(s); } } }
时间: 2024-12-15 06:53:21