ArrayIndexOutOfBoundsException — 배열 인덱스 범위 예외

ArrayIndexOutOfBoundsException — 배열 인덱스 범위 예외

ArrayIndexOutOfBoundsException은 배열이 잘못된 인덱스로 접근되었을 때 던져지는 예외입니다. 인덱스가 음수이거나 배열의 크기보다 크거나 같으면 발생합니다.

출처: Java API Reference

본문

이 클래스는 IndexOutOfBoundsException의 하위 클래스입니다.

public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException

생성자

public ArrayIndexOutOfBoundsException()
public ArrayIndexOutOfBoundsException(String s)
public ArrayIndexOutOfBoundsException(int index)
  • 기본 생성자는 상세 메시지 없이 예외를 만듭니다.
  • String s 생성자는 지정한 문자열을 상세 메시지로 사용합니다.
  • int index 생성자는 잘못된 인덱스 값을 상세 메시지의 일부로 사용합니다.

예를 들어 길이가 5인 배열의 인덱스 -1이나 5에 접근하면 이 예외가 발생합니다. 배열을 순회할 때 반복문의 경계 조건을 잘못 설정하는 것이 대표적인 원인입니다.

더 알아보기 (Learn more)