부트캠프 기록/Serction2

[JAVA] Collectors 와 Collections 차이

bbangduck 2022. 9. 28. 23:40
 //collectors와 Collections 차이
        ArrayList<Integer> list = (ArrayList<Integer>) Arrays.stream(stuff).boxed().collect(Collectors.toList());
        Collections.sort(list); //오름차순 정렬

 

Collectors

 

Collectors (Java Platform SE 8 )

Returns a Collector implementing a "group by" operation on input elements of type T, grouping elements according to a classification function, and returning the results in a Map. The classification function maps elements to some key type K. The collector p

docs.oracle.com

 

  • 컬렉션의 stream을 처리하는 클래스 
  • 어떤 요소를 어떤 컬렉션에 수집할 것인가를 나타냄
  • stream().collect() 메서드의 매개값

 

 

Collections

 

Collections (Java Platform SE 7 )

Rotates the elements in the specified list by the specified distance. After calling this method, the element at index i will be the element previously at index (i - distance) mod list.size(), for all values of i between 0 and list.size()-1, inclusive. (Thi

docs.oracle.com

 

  • collection(List, Map, Set) 에 대해서만 작동하거나 collection을 반환하는 클래스

 

 

 

 

참고