title: Why are Integers immutable in Java?
body: <p>I know Integers are immutable in Java. But why it is designed this way?</p>
  
  <p>I went through other answers before asking this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/5560176/is-integer-immutable">Is Integer Immutable</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16903637/i-still-working-for-immutable-integer-in-java">i++ still working for immutable Integer in Java?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12370544/why-are-java-wrapper-classes-immutable">Why are Java wrapper classes immutable?</a></p>
  
  <p>But I couldn't find the use case which mandates the Integer to be immutable.
  Are there any technical reasons like there are for String?</p>
  
  <ol>
  <li>String is used as parameter in network connection, database URLs etc. It could easily be compromised if it was mutable.</li>
  <li>To support StringPool facility.</li>
  <li>To support class loading mechanism in which Strings are used as arguments. String being mutable results in a wrong class being loaded.</li>
  </ol>
  
  <p>I understand there are wrappers like <code>AtomicInteger</code> for mutable.  </p>
  
  <p>UPDATE:</p>
  
  <p>From the conversation, there is no universal reason that could mandate the Integers being immutable. However by doing immutable it provides some bonus as mentioned in the answers.</p>
  
  <p>Such as this quote from <a href="https://stackoverflow.com/users/283676/andrey">Andrey</a></p>
  
  <blockquote>
    <p>possibility to cache. </p>
    
    <p>Others are reducing global state </p>
    
    <p>easier multithreading</p>
  </blockquote>