Imagine that I have this class:
public class Test
{
private String[] arr = new String[]{\"1\",\"2\"};
public String[] getArr()
{
return arr;
You could return a copy of the data. The caller who chooses to change the data will only be changing the copy
public class Test {
private static String[] arr = new String[] { "1", "2" };
public String[] getArr() {
String[] b = new String[arr.length];
System.arraycopy(arr, 0, b, 0, arr.length);
return b;
}
}