1.String is the basic data type of Java?
No, there are eight basic data types in Java: Int,byte,char,short,long,float,boolean,char. String is not a basic data type in Java, it is a reference type.
Java provides a wrapper class for each of the basic types, respectively, Int,byte,char,short,float,boolean,char.
Reference types and primitive types have different characteristics and behaviors, how they are stored, and their size and speed. The default value of a reference type is null and the default value of the base type is related to the specific type.
Extended:
The string is of the final type and is not allowed to be changed. It is placed in a constant pool, which is determined by the class during compilation and is saved in the. class file that is compiled, including constants inside classes and interfaces, and string constants. The following code snippet:
String s1= "ABCDE";
String s2= "ABCDE";
String s3= "abc" + "De";
System.out.println (S1==S2);
System.out.println (S2==S3);
The run result is true true
We know that = = is the same as the address the object is stored in, and equal is the same as the value of the object pointing to the address.
strings1= "ABCDE" at run time, the JVM first checks if there is a string in the string constant pool that has "ABCDE", assigns a reference to the string to S1 if it exists, creates the object in a constant pool if it does not exist, and assigns a reference to the object to S1. So the S1 and S2 re-compile phase has been determined, pointing to the same address.
The strings3= "abc" + "De", in which "abc" and "De" are constants, are processed as "ABCDE" during the compilation phase, and the JVM can find the string constant in the constant pool, so S3 points to the same address as S1 and S2.
The string created with the new string is not placed in the string constant pool because it cannot be determined by the compilation phase.
What is the difference between string and StringBuffer?
Java face question (i) string correlation