List<List<Integer>> 형태
1. 선언
List<List<Integer>> result = new ArrayList<>();
- 외부 List → 여러 개의 조합을 담는 리스트
- 2차원 리스트처럼 보이는 구조
- 내부 List<Integer> → 한 번의 조합(세 숫자)을 담는 리스트
List<List<Integer>> result;
result.add(Arrays.asList(1,2,3)); // ❌ NullPointerException 발생
- 초기화안하면 NullPointerException
- Why? null 상태에서 .add() 호출하면 에러
- 반드시 new ArrayList<>()
2. 추가하는 법 & 출력형태
import java.util.*;
public class Main {
public static void main(String[] args) {
List<List<Integer>> result = new ArrayList<>();
result.add(Arrays.asList(1, 2, 3));
result.add(Arrays.asList(4, 5, 6));
result.add(Arrays.asList(7, 8, 9));
System.out.println(result);
}
}
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]