In general, the basic data types are passed to the method, and when you pass an array to a method, you need to consider the allocation of memory
Public classTest2 { Public Static voidMain (String args[]) {intArr[] =New int[] {9,1,2,3,4,7,8,6,5 }; Sort (arr); for(intI=0; i<arr.length; i++) {System. out. println (Arr[i]); } } Public Static voidSortintArr[]) {//Bubble Sort for(intx=0; x<arr.length; X + +) { for(inty=0; y<arr.length-1; y++) { if(Arr[y] > arr[y+1]) { inttemp; Temp=Arr[y]; Arr[y]= arr[y+1]; Arr[y+1] =temp; } } } } }
Passing an array to a method, or passing the value of an array to another array, results in a new stack of memory. The change of the array in the reference will affect the original (in fact, the heap memory of the original array operation). When the reference operation is complete, the reference produces no more memory than the heap memory of the original array.
Java Basic Learning Path (vi) the transfer of arrays and method parameters