The first season of Java

Source: Internet
Author: User

Interview Question one:

The difference between String,stringbuffer,stringbuilder?
* A:string content is immutable, and stringbuffer,stringbuilder is content-changeable.
* B:stringbuffer is synchronous, data security, low efficiency; StringBuilder is out of sync, data is unsafe, high efficiency


Interview question two:

What is the difference between stringbuffer and arrays? And it is the most commonly used, functionally and stringbuffer exactly the same
* Both can be seen as a container for other data.
* But, StringBuffer's data is ultimately a string of data.
* While arrays can place a variety of data, but they must be different arrays of the same data type have different data types.


Interview question three:

Does the string type of data pass as a formal parameter change the actual parameters?

Through code Validation:

public Class Stringbufferdemo {public static void main (string[] args) {String S1 = "Hello"; String s2 = "World"; SYSTEM.OUT.PRINTLN (S1 + "---" + s2);//Hello---worldchange (s1, S2); SYSTEM.OUT.PRINTLN (S1 + "---" + s2);//Hello---worldstringbuffer sb1 = new StringBuffer ("Hello"); StringBuffer SB2 = new StringBuffer ("World"); System.out.println (SB1 + "---" + sb2);//Hello---worldchange (sb1, SB2); System.out.println (SB1 + "---" + sb2);//Hello---worldworld,}//method overload public static void Change (StringBuffer sb1, Stri Ngbuffer sb2) {sb1 = Sb2;//sb1=world, there is no change to the original SB1. Sb2.append (SB1);//append stitching mode. }public static void Change (string s1, string s2) {S1 = S2;s2 = s1 + s2;}} 
</pre><pre code_snippet_id= "1677075" snippet_file_name= "blog_20160510_3_2822793" name= "code" class= "Java" > Conclusion:
<pre name= "code" class= "Java" >/* string passed as parameter *  StringBuffer passed as parameter  *  * formal parameter: * Basic type: Change of formal parameter does not affect actual parameters * Reference type: Changes in formal parameters directly affect actual parameters *  * Note:
*<span style= "White-space:pre" ></span> Special case: * String reference type is passed as a parameter, and the effect and base type are passed as arguments. That is: changes in formal parameters affect actual parameter changes.

The next article begins to enter the arrays class.

The first season of Java

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.