List 람다식 처리 방식
2019. 10. 21. 00:38ㆍJava
반응형
람다식 처리 방식
someObjects.forEach(obj -> {
//what to do here?
})
MemberVO.java 생성
...더보기
package domain;
public class MemberVO {
private String id;
private String password;
private String username;
private String email;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "MemberVO [id=" + id + ", password=" + password + ", username=" + username + ", email=" + email + "]";
}
}
LambdaTest.java 생성
...더보기
import java.util.ArrayList;
import java.util.List;
import domain.MemberVO;
public class LambdaTest {
public static void main(String[] args) {
List<MemberVO> memberList = new ArrayList<MemberVO>();
for (int i = 0; i < 3; i++) {
MemberVO member = new MemberVO();
member.setId("admin"+i);
member.setPassword("pwd"+i);
member.setUsername("username"+i);
member.setEmail("admin"+i+"@naver.com");
memberList.add(member);
}
memberList.forEach(
(member) -> System.out.println(member)
);
}
}
실행 결과
반응형