I am trying to pass an array without using a reference, but directly with the values :
public static void main(String[] args){
int[] result = insertionSort({10,3,4,12,2});
}
public static int[] insertionSort(int[] arr){
return arr;
}
but it returns the following exception :
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token(s), misplaced construct(s)
Syntax error on token ")", delete this token
When I try the following code , it works , can anybody please explain the reason ?
public static void main(String[] args){
int[] arr = {10,3,4,12,2};
int[] result = insertionSort(arr);
}
public static int[] insertionSort(int[] arr){
return arr;
}
new int[20]or similar will do), then pass a null array to the method and print the array outside the method, it will still benull, that's because Java passes by value, not the reference of the object.