IndexOutOfBoundsException

Java

IndexOutOfBoundsException 완벽 정리 (초보자도 이해하는 자바 인덱스 오류 + 배열·리스트 코드 예제)

자바 개발하다 보면 배열이나 리스트 다루다가 한 번쯤은 꼭 터지는 예외가 있다.바로 IndexOutOfBoundsException 이다.이건 초보 때 진짜 많이 만나는 예외라서, 제대로 이해해두면 디버깅 속도가 확 올라간다.IndexOutOfBoundsException 이란?이름 그대로 해석하면 된다.👉 "인덱스 범위를 벗어났을 때 발생하는 예외"즉,배열 길이가 5인데 index 5를 접근했다리스트 크기가 3인데 index 10을 가져오려고 했다이럴 때 터진다.가장 기본적인 예제 (배열)public class Main { public static void main(String[] args) { int[] arr = {10, 20, 30}; System.out.println..

Coding_Slowly
'IndexOutOfBoundsException' 태그의 글 목록