728x90
Exception in thread "main" java.util.ConcurrentModificationException
at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1510)
at java.base/java.util.HashMap$KeyIterator.next(HashMap.java:1533)
at BOJ.Gold.g2.Test.main(Test.java:21)
간단하더라도 겪었던 오류들을 적어보려고 한다
해시 맵에서
for (int key: map.keySet()) {
if (key==2) map.remove(key);
}
와 같이 반복문을 돌던 중에 특정 값을 제거하거나 수정하려고 할 때 해당 오류가 발생한다
리스트에서는 제거하고 index 처리를 따로 하지 않으면 안에서 원하는 값이 안 나올때는 있지만 에러가 발생하진 않는데 HashMap에서는 에러가 발생하는 것 같다.
리스트로 바꾸고 index를 각각 처리하는 방식으로 수정하였다
728x90
'Trouble Shootings' 카테고리의 다른 글
[Vue.js] .env .local 값을 못 읽을 때 (403 error) (0) | 2022.11.20 |
---|---|
[intellij/spring] 인텔리제이 spring boot annotation "Cannot read symbol" (0) | 2022.11.20 |
[크롬 Chrome] 확장 프로그램 다운로드 / 실행 실패 (0) | 2022.11.07 |
[스프링 부트] 파일 업로드 시 static 정적 경로 설정 (0) | 2022.10.28 |
[스프링부트] Web server failed to start. Port 8080 was already in use. (0) | 2022.10.27 |