JAVA - ArrayList 간단하게 정렬(sort)하기(오름차순&내림차순)
·
JAVA/기타
개요 JAVA언어에서 자주 사용하는 컬렉션중 하나인 ArrayList 간단한 방법으로 정렬하기 1. Collections.sort() 2. List.sort() 3. Stream sorted() 1. Collections.sort() Java의 Collections 클래스는 ArrayList를 포함한 모든 컬렉션을 정렬하는 데 사용할 수 있는 sort() 메서드를 제공합니다. 오름차순으로 정렬하려면 인수 없이 sort() 메서드를 호출 내림차순으로 정렬하려면 Collections 클래스의 reverseOrder() 메서드를 sort()의 인수로 추가하여 호출 List numberList = new ArrayList(List.of(23, 1000, -1, 0, -55, 7)); Collections.sor..