반응형
! 기록을 위한 포스트입니다.
자바8이상에서 객체 리스트에서 특정필드에서 추출하는 코드는 다음과 같다.
// 예시용 DTO
@Getter
@Setter
class TestDto {
@ApiModelProperty(position = 1, value = "테스트번호", example = "1")
private Integer testNo;
@ApiModelProperty(position = 1, value = "테스트내용", example = "테스트내용입니다.")
private String testContent;
}
// TestDto의 번호만 추출하여 새로운 리스트 만들기
List<TestDto> testList = ...;
List<Integer> testNoList = testList.stream().map(TestDto::getTestNo).collect(Collectors.toList();
반응형
'Dev > etc' 카테고리의 다른 글
[구름IDE] Error: Unable to access jarfile 오류 해결방법 (0) | 2023.04.20 |
---|---|
[Unity] 안드로이드(android) playerprefs 위치(location) (0) | 2023.03.07 |
[Excel]microsoft.office.interop.excel.applicationclass' 오류 (0) | 2023.02.21 |
[CentOS7]리눅스 방화벽(firewall) 특정 IP 접근하는 방법 (0) | 2023.01.26 |
[Git] Git remote URL 변경하기 (원격 저장소 변경하기) (0) | 2020.03.23 |