Java Advanced Features (Basics)

  • 2020-06-23 00:29:09
  • OfStack

1, StringBuffer, StringBuilder, and String1 are also used to represent strings. The String class is immutable, and any change to String will cause the generation of new String objects. StringBuffer is a mutable class, and any change to the string it refers to does not create a new object. If you have mutable and immutable, why is there an StringBuilder? In the beginning, I believe you will always choose StringBuffer for append.

The same is true for the StringBuffer and StringBuilder classes, which work in the same way, except that StringBufferd supports concurrent operations, is linearly safe, and is suitable for multithreading. StringBuilder does not support concurrent operations, is linearly unsafe and is not suitable for use in multithreading. The new StringBuilder class is not thread-safe, but it performs better in a single thread than StringBuffer.

2. Wildcard generics can not only be restricted downward, for example < ? extends Collection > Can also limit upward, such as < ? super Double > , indicates that the type can only accept instances of Double and its upper parent types, such as Number and Object types.

In multiple inheritance, the initialization sequence is 1. Superclass attribute 2. Superclass constructor 3.

4. The write method of FileOutputStream has three types of parameter overloading, one of which is of type int. For this program fragment, syntax and call parameters are no problem, where fos.write (' a'), will automatically convert 'a' to int (ascii encoding), when the run is over, open the file with notepad, where should be character a.


Related articles: