Java Basic Learning Path (vi) the transfer of arrays and method parameters

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.