char and String Notes

char

  1. Java's char characters are two characters uses Unicode encoding can represent Chinese
  2. and char may be int, short, long integer installed for each type, which is to be stored as is their nature binary integer form, but during the transition needs attention caused by different lengths data lost.

String

  1. str1=new String("abc")与str2="abc"
    str1==str2是false
    str1.equse(str2)是true

The object literal pool

  1. Java5.0 from the beginning, Java virtual machine when it starts to instantiate nine object pool. They are used to store eight basic types of objects and packaging String object, primarily for efficiency. Understand the role of the concept of object pools and string the pool is very important, because only this can really flexible with the use of string data.
    ***
  2. str1 = "abc" is the constant pool to check there is no equivalent of the object, if not then create an object in the constant pool "abc" address and then assign the constant pool object str1 if used directly address assigned to str1, the new String ( "abc") is a constant pool to check there is no equivalent of the object, if not then create an object "abc" in the constant pool, and then create a "abc" in a heap of objects directly if a common "abc" object.
    ***
  3. Pooling is to avoid the frequent create and destroy objects and impact system performance. When the JVM is running the code to a string enclosed in double quotes, String object is to pool to see if the same sequence of characters in a subject. If so, get ready-made objects, if not, create an object in the object pool, and return.
    ***
  4. If a large amount of string concatenation and StringBuilder avoid using Stringbuffer create a large number of objects
    StringBuffer not thread-safe
    StringBuilder is thread-safe
    StringBuffer.reverse () string flip

Learn java programmers interview book

Guess you like

Origin www.cnblogs.com/lianqiqi/p/11028823.html