黑马程序员技术交流社区

标题: 增强型for循环遍历~看我起的名字 [打印本页]

作者: 琥珀主    时间: 2015-10-10 22:46
标题: 增强型for循环遍历~看我起的名字
  1. package com.heima.zuoye;

  2. import java.util.ArrayList;

  3. import com.heima.bean.Person;

  4. public class Demo4_StrongFor {
  5.         public static void main(String[] args) {
  6.                 //demo1();
  7.                 ArrayList<String> list = new ArrayList<>();
  8.                 list.add("lalala");
  9.                 list.add("hahaha");
  10.                 list.add("hehehe");
  11.                 list.add("eeeeee");
  12.                
  13.                 for(String s:list) {
  14.                         System.out.println(s);
  15.                 }
  16.         }

  17.         public static void demo1() {
  18.                 ArrayList<Person> list = new ArrayList<>();
  19.                 list.add(new Person("张三",23));
  20.                 list.add(new Person("李四",24));
  21.                 list.add(new Person("王五",25));
  22.                 list.add(new Person("赵六",26));
  23.                
  24.                 /*for(Person person:list) {
  25.                         System.out.println(person);
  26.                 }*/
  27.                 for (Person person : list) {
  28.                         System.out.println(person);
  29.                 }
  30.         }
  31. }
复制代码

作者: 邓士林    时间: 2015-10-10 22:57
几个意思啊!没看懂
作者: 仨儿先森    时间: 2015-10-10 23:01
头像碉堡了
作者: Q的感动    时间: 2015-10-27 22:24
能看懂一些




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2