class Testing{
private static int counter;
private static int[] intArray;
public static ReturnClassName className(File f){
ReturnClassName returnCN= new ReturnClassName();
byte[] b;
try{
DataInputStream dataIStream= new DataInputStream(new FileInputStream(f));
intArray= new int[dataIStream.available()];
b= new byte[dataIStream.available()];
dataIStream.read(b);
intArray= b;
// setting methods for ReturnClassName
// counter increment
returnCN.setNumber(someMethod(5));
}//catch() block
return returnCN;
}
private static int[] someMethod(int l){
return Arrays.copyOfRange(intArray, counter, counter + l);
}
Or
class Testing{
private static int counter;
public static ReturnClassName className(File f){
ReturnClassName returnCN= new ReturnClassName();
byte[] b;
try{
DataInputStream dataIStream= new DataInputStream(new FileInputStream(f));
intArray= new int[dataIStream.available()];
b= new byte[dataIStream.available()];
dataIStream.read(b);
intArray= b;
// setting methods for ReturnClassName
// counter increment
returnCN.setNumber(someMethod(intArray,5));
}//catch() block
return returnCN;
}
private static int[] someMethod(int[] iArray, int l){
return Arrays.copyOfRange(iArray, counter, counter + l);
}
I want to know which one is more optimized and safe of the above two codes. Also while passing the array in the 2nd code, is it passing the whole array or just the address of that array. Like both intArray and iArray are pointing to the same integer array?