iterator #
![[JAVA] ConcurrentModificationException 오류 원인 및 해결 방법](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbiOyYO%2FbtrA2CXZXs2%2FK3UCRjLxPZfANvCwsEscl1%2Fimg.png)
[JAVA] ConcurrentModificationException 오류 원인 및 해결 방법
프로그래머스 문제를 풀다가 ConcurrentModificationException 예외가 발생했다. 이 예외는 list나 ArrayList를 for문에 직접 넣어서 돌다가 remove를 호출하면 발생한다. for문에서 돌아가는 list가 remove를 호출하면 크기가 줄어들게 되고 size값이 맞지 않기 때문에 발생한다. 예를들면 ArrayList list = new ArrayList(); for(rep : list){ if(rep.equals("sanha")){ list.remove(rep); System.out.println(rep+ "는 sanha 삭제할게요~") } } 해결법. ArrayList list = new ArrayList(); Iterator iter = list.iterator();..