title: Why is String immutable in Java?
body: <p>I was asked in an interview why String is immutable</p>
  
  <p>I answered like this:</p>
  
  <blockquote>
    <p>When we create a string in java like <code>String s1="hello";</code> then an
    object will be created in <strong>string pool(hello)</strong> and <strong>s1</strong> will be
    pointing to <strong>hello</strong>.Now if again we do <code>String s2="hello";</code> then
    another object will not be created but <strong>s2</strong> will point to <code>hello</code>
    because <strong>JVM</strong> will first check if the same object is present in
    <strong>string pool</strong> or not.If not present then only a new one is created else not.</p>
  </blockquote>
  
  <p>Now if suppose java allows string mutable then if we change <strong>s1</strong> to <code>hello world</code> then <strong>s2</strong> value will also be <code>hello world</code> so java String is immutable.</p>
  
  <p>Can any body please tell me if my answer is <strong>right</strong> or <strong>wrong</strong>?</p>