title: How do I prevent the modification of a private field in a class?
body: <p>Imagine that I have this class:</p>
  
  <pre><code>public class Test
  {
    private String[] arr = new String[]{"1","2"};    
  
    public String[] getArr() 
    {
      return arr;
    }
  }
  </code></pre>
  
  <p>Now, I have another class that uses the above class:</p>
  
  <pre><code>Test test = new Test();
  test.getArr()[0] ="some value!"; //!!!
  </code></pre>
  
  <p>So this is the problem: I have accessed a private field of a class from outside!
  How can I prevent this? I mean how can I make this array immutable? Does this mean that with every getter method you can work your way up to access the private field? (I don't want any libraries such as Guava. I just need to know the right way to do this).</p>