黑马程序员技术交流社区

标题: 存储 [打印本页]

作者: 阿杜    时间: 2016-5-5 21:10
标题: 存储
把集合中存储多个Person对象,Person有姓名和年龄,找出年龄最大的
作者: 阿杜    时间: 2016-5-5 21:11
  public static void main(String[] args) {
                 ArrayList<Person> list = new ArrayList<>();
                 list.add(new Person("德玛血压",60));
                 list.add(new Person("德邦莽夫",23));
                 list.add(new Person("皇子小三",28));
                 list.add(new Person("剑圣求败",53));
                 list.add(new Person("诺克掉渣",30));
                 Person p =new Person();

                 ListIterator<Person> it = list.listIterator();
                 int  max = list.get(0).getAge();
                         p = list.get(0);
                 for (Person person : list) {
                         if (max < person.getAge()) {
                                 max =person.getAge() ;
                                 p = person;
                         }
                        
                 }        
                 System.out.println(p);        
                 
         }
}

作者: 阿杜    时间: 2016-5-5 21:13
怎么样呢
作者: 艺高人胆大    时间: 2016-5-5 21:16
??????我想想啊
作者: 阿杜    时间: 2016-5-5 21:37
艺高人胆大 发表于 2016-5-5 21:16
??????我想想啊

把lol的思想加入就有意思了




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