I was wondering, in java, is it possible, in any case, to simulate passing by reference to an array? Yes, I know, the language does not support it, but I can do it anyway. Say, for example, I want to create a method that reorders all the elements in an array. (I know this piece of code is not a good example, as there are better algorithms for this, but it is a good example of what I want to do for more complex problems).
Currently I need to make a class like this:
public static void reverse(Object[] arr) {
Object[] tmpArr = new Object[arr.length];
count = arr.length - 1;
for(Object i : arr)
tmpArr[count--] = i;
for(Object i : tmpArr)
arr[count++] = i;
return;
}
Yes, I know that I can just change the values until I get to the middle, and that would be much more efficient, but for other, more complex purposes, is there still that I can manipulate the actual pointer?
Thanks again.