title: JAVA - HashMap check specific key value (if greater)
body: <pre><code>Map&lt;Integer, Integer&gt; listInfo = new HashMap&lt;Integer, Integer&gt;();
  </code></pre>
  
  <p>I have been trying to search from Google, but I don't really know why I cannot find a correct solution. Anyways my HashMap will store two Integers. I would use normal "int[]" string-list or whatever it is called for, but it will return me exception something about "array outofbounds" or something related to that, because it's index will be greater than int. Not sure, but anyways let's stay in the topic.</p>
  
  <p>My english is pretty bad, but if you don't understand what I'm talking about hope this helps. <strong>(Just the idea, not based in real code)</strong></p>
  
  <pre><code>if(listInfo.containsKey(key)) {
      if(listInfo.getKeyValue(key).valueOfKey() &gt; valueToBeAdded) {
          listInfo.put(key, valueToBeAdded);
      }
  } else {
      listInfo.put(key, valueToBeAdded);
  }
  </code></pre>
  
  <p>I have tried similar way than above, but with pretty much correct functions, but it will conflict, because it says that it cannot compare key value with int, because key value is object? Why it's object, because I've defined that it should be Integer? I've also tried for(Entry entry : ......) loop, but I have no clue how I can get specific key's value (I am not talking about key value, I'm talking about value that the specific key holds)</p>
  
  <p>I want only update the value that the specific (existing) key holds if the value that key holds is greater and the value that will be added is less than the current one.</p>