Learning JAVA programming ideas (chapter thirteen) strings

Whenever a String object is passed as a parameter to a method, a reference is made. The object to which the reference refers has actually been in a single physical location and has never been moved.

String objects are immutable, you can add any number of aliases to a String object, because String objects are read-only, so any reference to it cannot change its value, so it will not have any reference to other references. what impact

String + String is the only operator overloading in JAVA, and it is also done internally with StringBuilder, but if you encounter complex string splicing, such as loops: it is more efficient to use StringBuilder. The + sign method creates a StringBuilder each time the loop is looped. In addition, use the append() method of StringBuilder, and do not use the following way of writing. For example: append(a+":"+c) This will fall into a trap, and the underlying implementation will create StringBuilder multiple times.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326337953&siteId=291194637