xl_echo编辑整理

百战不败,依不自称常胜,百败不颓,依能奋力前行。——这才是真正的堪称强大!!


开发工具IDEA

package com.echo.demo;

import java.util.ArrayList;
import java.util.List;

/**
* Created by Xlecho on 2018/6/4/004
*/
public class A {

public static void main(String[] args){
List<B> list = new ArrayList<>();
B a = new B();
a.setAge(22);
a.setName("a");
list.add(a);

B a1 = new B();
a1.setAge(22);
a1.setName("a1");
list.add(a1);

list.forEach(aa -> {
System.out.println(aa.getAge() + aa.getName());
});
}

static class B{
private Integer age;
private String name;
public void setAge(Integer age){
this.age = age;
}
public Integer getAge(){
return age;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
}

}

输出结果

JDK1.8--遍历一个集合取集合中对象的值_JDK1.8