[자바 컬렉션과 Stream] 81. 정렬(Sort)

김건우's avatar
Feb 19, 2025
[자바 컬렉션과 Stream] 81. 정렬(Sort)
💡
Sort
퀵 정렬, 합병 정렬, 히프 정렬 등의 다양한 방법이 존재하지만,
Collections 클래스의 정렬은 속도가 비교적 빠르고 안정성이 보장되는 합병 정렬 이용

문자열 정렬하기

package ex16; import java.util.*; public class Sort { public static void main(String[] args) { String[] a = {"i", "love", "leetcode", "the"}; List<String> list = Arrays.asList(a); // 배열을 리스트로 변경 Collections.sort(list); // 역순으로 정렬하려면 Collections.sort(list, Collections.reverseOrder()); System.out.println(list); } }
notion image
Share article

gunwoo