- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- public class OutputWayDemo {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- List<String> list = new ArrayList<String>();
- list.add("30");
- list.add("11");
- list.add("25");
- list.add("66");
- System.out.println(list);
- Iterator<String> it = list.iterator();
- while (it.hasNext()) {
- System.out.println("迭代器输出:" + it.next());
- }
- for (String str : list) {
- System.out.println("for高级循环输出:" + str);
- }
- int i = 0;
- for (Iterator<String> iter = list.iterator(); i < list.size(); i++) {
- System.out.println("for循环输出:" + iter.next());
- }
- Object[] obj = list.toArray();
- for (Object o : obj) {
- System.out.println("集合转为数组输出:" + o);
- }
- }
- }
复制代码
|
|