배열을 고정 크기의 리스트로 변환하는 메서드
String[] array = {"a", "b", "c"};
List<String> list = Arrays.asList(array);
System.out.println(list); // [a, b, c]
단, AsList 로 리스트를 초기화하게 되면 원소를 추가하거나 삭제할 수 없다.
class Solution {
public String solution(String[] seoul) {
return "김서방은 " + Arrays.asList(seoul).indexOf("Kim") + "에 있다";
}
}
다음과 같이 배열을 리스트 형태로 변환하고 인덱스 값을 추출할 수 있다.