Addressing your last sentence. You can easily have the identifier point to a different array.
Here's the skeleton of what you want:
public int[] shortArr( int[] longArr ) {
...int shorter = // some length to be determined
...int[] retArr = new int[shorter];
// logic to fill the retArr
...return retArr;
}
Then in your invoking method
int[] longArr = { 1,7,8,24,44 100, 72,...}; // whatever that array is
longArr = shortArr( longArr );
and now longArr points to the array returned by your method.
+add
A comment about Ratchetr's post. You have a choice. If you want the original name to point to the new, shorter array then do what I wrote in that last statement. If you want to keep the old array then use
int[] shorterArr = shortArr( longArr );
Your choice.
++add
I interpret:
"But I need to make it so that after this method is called, any reference to the original array would be referring to the shorter one."
to mean that the identifier would now point to the newer, shorter array. That is what would happen with my last statement, repeated here:
longArr = shortArr( longArr );
In a way, this is similar to what the String method substring CAN do:
String str = new String( "a big ole string" );
str = str.substring( 0, 5 );
now str is "a big"
The original string is gone, the identifier points to a different string. You can also say:
str = "a different animal";
and now the same identifer points to still another string. Object identifiers can be reassigned, ie, point to a different object.
In retrospect I see that I shouldn't have given that method a name so similar to the arrays that's it's involved with!!
+++add
Now I see what you're getting at with 'ANY'. I don't think that is what's meant. I think that what is meant is that of the same identifer pointing to a shorter array.
+iv add
Wow, there's a method in the Arrays class to do exactly what you want:
int[] shortArr = Arrays.copyOf( original, newLength );
This will produce an array that only have the first newLength elements of the original array.
http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#copyOf(int[], int)