@[toc]
The initial value of String
When a String is a class variable, its initial value is null, with or without the static prefix
When a String is used as a variable in a method, if an initial value is not assigned, an error will be detected before it is run, indicating that an initial value is required
IsEmpty () found empty
The method used to determine if a string is empty, of course the empty value is not null “”, as follows
String str = "";
System.out.println(str.isEmpty());
Copy the code
The final return is true, and an error will be reported before the run if STR has no initial value, or a null pointer exception will be raised by calling isEmpty() at run time if STR has an initial value of null
Nulls compared to NULL
String is not manually assigned as a class variable. Its initial value is null, which indicates that no space has been allocated, and “” which indicates that space has been allocated
String str = null;
System.out.println(str==null);
Copy the code
The final output is true, and null-pointer exceptions will occur if the null STR calls some methods in the String class
Equals (” “) found empty
Instead of using isEmpty(), equals(“”) can do the same thing
String str = "";
System.out.println(str.equals(""));
Copy the code
Returns true
(String)null
I haven’t used this method before, but I looked at jedis source code and found that when creating redis connection pool, if the password is not passed, the password will be passed by (String)null
(String)null = null (String)null = null; (String)null = null