{"id":79156,"date":"2020-06-23T09:00:35","date_gmt":"2020-06-23T03:30:35","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=79156"},"modified":"2020-06-23T09:00:35","modified_gmt":"2020-06-23T03:30:35","slug":"java-concurrentmodificationexception","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/","title":{"rendered":"How to Avoid ConcurrentModificationException in Java"},"content":{"rendered":"<p>In this article, we will study a predefined Exception in Java which is ConcurrentModificationException. It is a very common exception that occurs while working with Collections in Java. You must know this exception and how to handle the same.<\/p>\n<p>We will study this Exception with examples and the ways to avoid this exception.<\/p>\n<h3>ConcurrentModificationException in Java<\/h3>\n<p>Whenever we try to modify an object concurrently without permission, then the ConcurrentModificationException occurs. We often face this exception usually when we are working with Collection classes of Java. This exception is present in the java.util package.<\/p>\n<p>The Collection classes of Java are very fail-fast and if we try to change them while some thread is traversing over it using an iterator, then we will get a ConcurrentModificationException from iterator.next() method.<\/p>\n<p>The Concurrent modification exception can occur in the multithreaded as well as a single-threaded Java programming environment.<\/p>\n<p>Let\u2019s take an example. A thread is not permitted to modify a Collection when some other thread is iterating over it because the result of the iteration becomes undefined with it.<\/p>\n<p>Some implementations of the Iterator class throw this exception, including all those general-purpose implementations of Iterator that JRE provides.<\/p>\n<p>Such Iterators that do this are called fail-fast because they throw the exception as soon as they encounter such a situation rather than facing undetermined behavior of the Collection any time in the future.<\/p>\n<p><em><strong>Note:<\/strong><\/em><br \/>\nIt is not necessary that this exception will occur only when some other thread tries to modify a Collection object. It can also occur if the methods of a single thread are trying to violate the contract of the object.<\/p>\n<h3>Example of Java ConcurrentModificationException<\/h3>\n<p>Now, let us discuss the Java concurrent modification exception with the help of an example.<\/p>\n<p><strong>Code 1 to explain ConcurrentModificationException:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">package com.techvidvan.concurrentmodificationexception;\nimport java.awt.List;\nimport java.util. * ;\npublic class ConcurrentModificationException {\n  public static void main(String[] args) {\n    ArrayList &lt; Integer &gt; list = new ArrayList &lt; &gt;();\n\n    list.add(1);\n    list.add(2);\n    list.add(3);\n    list.add(4);\n    list.add(5);\n\n    Iterator &lt; Integer &gt; iterator = list.iterator();\n    while (iterator.hasNext()) {\n      Integer value = iterator.next();\n      System.out.println(\"The value of the List is:\" + value);\n      if (value.equals(3)) list.remove(value);\n    }\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The value of the List is:1<br \/>\nThe value of the List is:2<br \/>\nThe value of the List is:3<br \/>\nException in thread &#8220;main&#8221; java.util.ConcurrentModificationException<br \/>\nat java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)<br \/>\nat java.util.ArrayList$Itr.next(ArrayList.java:851)<br \/>\nat ConcurrentModificationException.main(ConcurrentModificationException.java:18)<\/div>\n<p>The above output message says that the exception occurs when we call the next method as the iterator is iterating the list and we are making modifications in it simultaneously.<\/p>\n<p>But if we make changes in the hashmap like the code below, then it will not throw any such exception as the size of the hashmap won&#8217;t change. So let\u2019s see this example.<\/p>\n<p><strong>Code to remove the exception from the above program:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">package com.techvidvan.concurrentmodificationexception;\nimport java.awt.List;\nimport java.util. * ;\npublic class concurrentModificationException {\n  public static void main(String[] args) {\n    HashMap &lt; Integer,\n    Integer &gt; map = new HashMap &lt; &gt;();\n    map.put(1, 1);\n    map.put(2, 2);\n    map.put(3, 3);\n\n    Iterator &lt; Integer &gt; it = map.keySet().iterator();\n    while (it.hasNext()) {\n      Integer key = it.next();\n      System.out.println(\"The Map Value is: \" + map.get(key));\n      if (key.equals(2)) {\n        map.put(1, 4);\n      }\n    }\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">The Map Value is: 1<br \/>\nThe Map Value is: 2<br \/>\nThe Map Value is: 3<\/div>\n<p><strong>Code 2 to explain ConcurrentModificationException:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">package com.techvidvan.concurrentmodificationexception;\nimport java.util.ArrayList;\nimport java.util.HashMap;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\n\npublic class ConcurrentModificationExceptionExample {\n  public static void main(String args[]) {\n    List &lt; String &gt; myList = new ArrayList &lt; String &gt; ();\n\n    myList.add(\"1\");\n    myList.add(\"2\");\n    myList.add(\"3\");\n    myList.add(\"4\");\n    myList.add(\"5\");\n\n    Iterator &lt; String &gt; it = myList.iterator();\n    while (it.hasNext()) {\n      String value = it.next();\n      System.out.println(\"List Value:\" + value);\n      if (value.equals(\"3\")) myList.remove(value);\n    }\n\n    Map &lt; String,\n    String &gt; myMap = new HashMap &lt; String,\n    String &gt; ();\n    myMap.put(\"1\", \"1\");\n    myMap.put(\"2\", \"2\");\n    myMap.put(\"3\", \"3\");\n\n    Iterator &lt; String &gt; it1 = myMap.keySet().iterator();\n    while (it1.hasNext()) {\n      String key = it1.next();\n      System.out.println(\"Map Value:\" + myMap.get(key));\n      if (key.equals(\"2\")) {\n        myMap.put(\"1\", \"4\");\n        \/\/ myMap.put(\"4\", \"4\");\n      }\n    }\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">List Value:1<br \/>\nList Value:2<br \/>\nList Value:3<br \/>\nException in thread &#8220;main&#8221; java.util.ConcurrentModificationException<br \/>\nat java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)<br \/>\nat java.util.ArrayList$Itr.next(ArrayList.java:851)<br \/>\nat<br \/>\ncom.techvidvan.ConcurrentModificationException.ConcurrentModificationExceptionExample.main(ConcurrentModificationExceptionExample.java:22)<\/div>\n<p>From the output message, it is clear that the concurrent modification exception occurs when we try to call the iterator next() method.<\/p>\n<p>You must be thinking how the Iterator checks for the modification, this is because the implementation of Iterator is present in AbstractList class where an int variable, modCount is present with the definition.<\/p>\n<p>The modCount variable provides the number of times list size is changed. Every next() call used the modCount variable to check for any modifications in a function checkForComodification().<\/p>\n<h3>Constructors of ConcurrentModificationException<\/h3>\n<p>There are 4 types of constructors of ConcurrentModificationException which are given in the following table:<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>S.N<\/b><\/td>\n<td><b>Constructor<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">1.<\/span><\/td>\n<td><span style=\"font-weight: 400\">public ConcurrentModificationException()<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a ConcurrentModification Exception with no parameters.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">2.<\/span><\/td>\n<td><span style=\"font-weight: 400\">public ConcurrentModificationException(String message)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a ConcurrentModification Exception with a detailed message of the Exception.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">3.\u00a0<\/span><\/td>\n<td><span style=\"font-weight: 400\">public ConcurrentModificationException(Throwable cause)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This constructor creates a ConcurrentModification Exception with a cause of the exception and a message which is (cause==null?null:cause.toString()). We can later retrieve this\u00a0 message by using Throwable.getCause().<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">4.<\/span><\/td>\n<td><span style=\"font-weight: 400\">public ConcurrentModificationException(String message, Throwable cause)<\/span><\/td>\n<td><span style=\"font-weight: 400\">This\u00a0 constructor creates a ConcurrentModification Exception with a cause and detailed message. We can retrieve this\u00a0 message using Throwable.getMessage() and the cause by Throwable.getCause().<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>How to avoid ConcurrentModificationException in a multi-threaded environment?<\/h3>\n<p>We can follow some precautions or ways to avoid ConcurrentModificationException in a multi-threaded environment:<\/p>\n<p><strong>1.<\/strong> We can iterate over the array instead of iterating over the collection class. Following this way, we can work very well with small-sized lists, but this will degrade the performance if the array size is very large.<\/p>\n<p><strong>2.<\/strong> Locking the list by putting it in the synchronized block is another way to avoid the concurrent modification exception. This is not an effective approach; it is not using the sole purpose of multi-threading.<\/p>\n<p><strong>3.<\/strong> The classes ConcurrentHashMap and CopyOnWriteArrayList of JDK 1.5 or higher versions can also help us in avoiding concurrent modification exceptions.<\/p>\n<h3>How To Avoid Concurrent Modification Exception in a single-threaded environment?<\/h3>\n<p>We can also avoid the Concurrent Modification Exception in a single threaded environment. We can use the remove() method of Iterator to remove the object from the underlying collection object. But in this case, you can remove only the same object and not any other object from the list.<\/p>\n<p><strong>Code to understand above concept:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">package com.technvidvan.concurrentmodificationexception;\nimport java.util.Iterator;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.CopyOnWriteArrayList;\n\npublic class AvoidConcurrentModificationException {\n  public static void main(String[] args) {\n    List &lt; String &gt; myList = new CopyOnWriteArrayList &lt; String &gt; ();\n\n    myList.add(\"1\");\n    myList.add(\"2\");\n    myList.add(\"3\");\n    myList.add(\"4\");\n    myList.add(\"5\");\n\n    Iterator &lt; String &gt; it = myList.iterator();\n    while (it.hasNext()) {\n      String value = it.next();\n      System.out.println(\"List Value:\" + value);\n      if (value.equals(\"3\")) {\n        myList.remove(\"4\");\n        myList.add(\"6\");\n        myList.add(\"7\");\n      }\n    }\n    System.out.println(\"List Size:\" + myList.size());\n\n    Map &lt; String,\n    String &gt; myMap = new ConcurrentHashMap &lt; String,\n    String &gt; ();\n    myMap.put(\"1\", \"1\");\n    myMap.put(\"2\", \"2\");\n    myMap.put(\"3\", \"3\");\n\n    Iterator &lt; String &gt; it1 = myMap.keySet().iterator();\n    while (it1.hasNext()) {\n      String key = it1.next();\n      System.out.println(\"Map Value:\" + myMap.get(key));\n      if (key.equals(\"1\")) {\n        myMap.remove(\"3\");\n        myMap.put(\"4\", \"4\");\n        myMap.put(\"5\", \"5\");\n      }\n    }\n    System.out.println(\"Map Size:\" + myMap.size());\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">List Value:1<br \/>\nList Value:2<br \/>\nList Value:3<br \/>\nList Value:4<br \/>\nList Value:5<br \/>\nList Size:6<br \/>\nMap Value:1<br \/>\nMap Value:2<br \/>\nMap Value:4<br \/>\nMap Value:5<br \/>\nMap Size:4<\/div>\n<h3>Using of loop to avoid ConcurrentModificationException<\/h3>\n<p>We can also use the for loop rather than an iterator to avoid concurrent modification exceptions in a single-threaded environment. We can ensure that our code takes care of the extra added objects in the list.<\/p>\n<p><strong>Code to use for loop to remove Concurrent Modification Exception:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">package com.technvidvan.concurrentmodificationexception;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.concurrent.ConcurrentHashMap;\nimport java.util.concurrent.CopyOnWriteArrayList;\npublic class AvoidConcurrentModificationException {\n  public static void main(String[] args) {\n    List &lt; String &gt; myList = new CopyOnWriteArrayList &lt; String &gt; ();\n\n    myList.add(\"1\");\n    myList.add(\"2\");\n    myList.add(\"3\");\n    myList.add(\"4\");\n    myList.add(\"5\");\n\n    for (int i = 0; i &lt; myList.size(); i++) {\n      System.out.println(\"List value: \" + myList.get(i));\n      if (myList.get(i).equals(\"3\")) {\n        myList.remove(i);\n        i--;\n        myList.add(\"6\");\n      }\n    }\n    System.out.println(\"List Size:\" + myList.size());\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">List value: 1<br \/>\nList value: 2<br \/>\nList value: 3<br \/>\nList value: 4<br \/>\nList value: 5<br \/>\nList value: 6<br \/>\nList Size:5<\/div>\n<p>The ConcurrentModificationException will occur if you try to modify the structure of the original list with the subList. Let\u2019s see this with a simple example.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">package com.technvidvan.concurrentmodificationexception;\nimport java.util.ArrayList;\nimport java.util.List;\npublic class ConcurrentModificationExceptionWithArrayListSubList {\n  public static void main(String[] args) {\n\n    List &lt; String &gt; names = new ArrayList &lt; &gt;();\n    names.add(\"Java\");\n    names.add(\"PHP\");\n    names.add(\"SQL\");\n    names.add(\"Angular 2\");\n\n    List &lt; String &gt; first2Names = names.subList(0, 2);\n\n    System.out.println(names + \" , \" + first2Names);\n\n    names.set(1, \"JavaScript\");\n    \/\/ check the output below. :)\n    System.out.println(names + \" , \" + first2Names);\n\n    \/\/ Let's modify the list size and get ConcurrentModificationException\n    names.add(\"NodeJS\");\n    System.out.println(names + \" , \" + first2Names); \/\/ this line throws exception\n\n  }\n}<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[Java, PHP, SQL, Angular 2] , [Java, PHP]<br \/>\n[Java, JavaScript, SQL, Angular 2] , [Java, JavaScript]<br \/>\nException in thread &#8220;main&#8221; java.util.ConcurrentModificationException<br \/>\nat java.util.ArrayList$SubList.checkForComodification(ArrayList.java:1231)<br \/>\nat java.util.ArrayList$SubList.listIterator(ArrayList.java:1091)<br \/>\nat java.util.AbstractList.listIterator(AbstractList.java:299)<br \/>\nat java.util.ArrayList$SubList.iterator(ArrayList.java:1087)<br \/>\nat java.util.AbstractCollection.toString(AbstractCollection.java:454)<br \/>\nat java.lang.String.valueOf(String.java:2994)<br \/>\nat java.lang.StringBuilder.append(StringBuilder.java:131)<br \/>\nat com.techvidvan.concurrentmodificationexception.ConcurrentModificationExceptionWithArrayListSubList.main(ConcurrentModificationExceptionWithArrayListSubList.java:23)<\/div>\n<h3>Conclusion<\/h3>\n<p>This was all about ConcurrentModificationException in Java. We discussed the cause for occurring this exception and discussed different ways to deal with this exception.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will study a predefined Exception in Java which is ConcurrentModificationException. It is a very common exception that occurs while working with Collections in Java. You must know this exception and&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":79178,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[2922,2923,2924,2925],"class_list":["post-79156","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-concurrentmodificationexception","tag-concurrentmodificationexception-java","tag-java-concurrentmodificationexception","tag-java-util-concurrent-modification-exception"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Avoid ConcurrentModificationException in Java - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn what is concurrentmodificationexception in Java and its constructors,examples to see when it occurs,ways to avoid java concurrentmodificationexception\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Avoid ConcurrentModificationException in Java - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn what is concurrentmodificationexception in Java and its constructors,examples to see when it occurs,ways to avoid java concurrentmodificationexception\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-23T03:30:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/ConcurrentModificationException-in-Java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Avoid ConcurrentModificationException in Java - TechVidvan","description":"Learn what is concurrentmodificationexception in Java and its constructors,examples to see when it occurs,ways to avoid java concurrentmodificationexception","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/","og_locale":"en_US","og_type":"article","og_title":"How to Avoid ConcurrentModificationException in Java - TechVidvan","og_description":"Learn what is concurrentmodificationexception in Java and its constructors,examples to see when it occurs,ways to avoid java concurrentmodificationexception","og_url":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-06-23T03:30:35+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/ConcurrentModificationException-in-Java.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"How to Avoid ConcurrentModificationException in Java","datePublished":"2020-06-23T03:30:35+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/"},"wordCount":1075,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/ConcurrentModificationException-in-Java.jpg","keywords":["concurrentmodificationexception","concurrentmodificationexception java","Java concurrentmodificationexception","java util concurrent modification exception"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/","url":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/","name":"How to Avoid ConcurrentModificationException in Java - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/ConcurrentModificationException-in-Java.jpg","datePublished":"2020-06-23T03:30:35+00:00","description":"Learn what is concurrentmodificationexception in Java and its constructors,examples to see when it occurs,ways to avoid java concurrentmodificationexception","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/ConcurrentModificationException-in-Java.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/06\/ConcurrentModificationException-in-Java.jpg","width":802,"height":420,"caption":"ConcurrentModificationException in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-concurrentmodificationexception\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"How to Avoid ConcurrentModificationException in Java"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=79156"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/79156\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/79178"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=79156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=79156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=79156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}