title: Access and modify the next entry set while iterating a map in Java
body: <p>While working on a problem statement, I need to access the next <code>Entry</code> of a <code>Map</code> and based on a condition, I need to modify the next entry value.</p>
  
  <p>I have been considering the solution provided here: <a href="https://stackoverflow.com/questions/30099237/how-to-get-the-previous-key-value-and-the-next-key-value-in-maps">How to get the previous key/value and the next key/value in Maps</a> where I can access the <code>higherEntry</code> using <code>NavigableMap</code> but it throws: </p>
  
  <pre><code>Exception in thread "main" java.lang.UnsupportedOperationException
      at java.util.AbstractMap$SimpleImmutableEntry.setValue(AbstractMap.java:797)
  </code></pre>
  
  <p>which is totally understood. Here is the code snippet</p>
  
  <pre><code>for (Map.Entry&lt;Character, Integer&gt; current : myMap.entrySet()) {
  
      Map.Entry&lt;Character, Integer&gt; next = myMap.higherEntry(current.getKey());
  
      if (current.getValue() == next.getValue()) {
          // Code block
      } else if (current.getValue() &gt; next.getValue()) {
          // Code block
      } else {
          next.setValue(1); // Line that throws Exception
      }
  }
  </code></pre>
  
  <p>How can I Iterate through a <code>Map</code>, access and modify the next Entry when required?</p>