평소 코딩테스트를 하면서 Collection을 쓸 일이 많은데 기존 배열을 한 번에 넣는 방법을 몰라서 반복문을 통해서 집어넣었습니다. 하지만 이 경우에는 코드가 지저분해 보일 수 있기 때문에 기존에 주어진 배열을 Collection에 넣으면 코드가 깔끔해집니다.
ArrayList<Integer> list = Arrays.stream(scovile)
.boxed()
.collect(Collectors.toCollection(ArrayList::new));
Arrays.stream(arr) - 선언
.boxed().sorted() - 가공
.collect(Collectors.toList()) - 반환
arr 배열을 정렬 후 List 타입으로 반환
라는 과정을 거친다.