은은하게 코드 뿌시기

스트림 리스트 안에 특정 dto 요소 조회 본문

자바/자바 기본

스트림 리스트 안에 특정 dto 요소 조회

은은하게미친자 2024. 2. 22. 11:21
728x90
            
        List<Box> anotherBoxList = BoxRepository.findByAnotherProductBox();

        for (Box anotherBox : anotherBoxList) {

            BoxListResponseDto BoxListResponseDto =
                    BoxListResponseDto.builder()
                            .id(anotherBox.getBoxNum())
                            .build();

            // 중복제거      
            boolean isIdExists
  = BoxListResponseDtos
                                              .stream()
                                              .anyMatch(Box ->  Box.getId().equals(anotherBox.getBoxNum()));
            if (!isIdExists){            
                BoxListResponseDtos.add(BoxListResponseDto);
            }                                
           
        }

 

728x90

'자바 > 자바 기본' 카테고리의 다른 글

자바 레이블 :{} !  (0) 2024.08.29
aws 서버로그 보기  (0) 2024.03.25
Enum(Enumeration)  (0) 2023.04.18
자바 - 람다식 (Lambda expression) 기초  (0) 2023.03.03
[java] @Target , @Retention/메타애너테이션  (0) 2022.12.01
Comments