String type passing is a value pass, and char[] type passing is an implementation of a reference pass _java

Source: Internet
Author: User

As shown below:

Package com.lstc.test;

public class TestDemo3 {
	String str = new String ("Hello");
	char[] ch = {' A ', ' B '};

	public static void Main (string[] args) {
		TestDemo3 t = new TestDemo3 ();
		T.change (T.str, t.ch);//string is the encapsulated class, is the value pass, and the char array is the reference pass
		System.out.println (T.str + "and" + t.ch[0] + t.ch[1);
	} Public

	void Change (String str, char[] ch) {
		str = ' Test ok ';
		Ch[0] = ' C ';
	}
}

The result: STR is still the first element of Hello,ch, a into C.

The above is a small series for you to bring the string type is the value of delivery, char[] Type pass is a reference to the implementation of the full content of the realization, I hope to help you, a lot of support cloud Habitat Community ~

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.