stream ()

ims·2020년 11월 10일
0

Java 정리 !

목록 보기
5/16

정리 블로그

https://beomseok95.tistory.com/218
https://dpdpwl.tistory.com/81

stream().filter 연습

public class ScratchPad {
    public static void main(String[] args) {

        List<Artist> artistList = new ArrayList<>();

        Artist artist1 = new Artist("얼수",10);
        Artist artist2 = new Artist("ims",20);
        Artist artist3 = new Artist("철수",30);
        Artist artist4 = new Artist("짱구",40);
        Artist artist5 = new Artist("짱아",50);

        artistList.add(artist1);
        artistList.add(artist2);
        artistList.add(artist3);
        artistList.add(artist4);
        artistList.add(artist5);

        List<Artist> newArtist = artistList.stream().filter(item->item.view>=30).collect(Collectors.toList());

        for(Artist a : newArtist){
            System.out.println(a.name);
        }
    }
}

class Artist{
    String name;
    Integer view;

    Artist(String name,Integer view){
        this.name=name;
        this.view=view;
    }
}
profile
티스토리로 이사했습니다! https://imsfromseoul.tistory.com/ + https://camel-man-ims.tistory.com/

0개의 댓글