What about Java null objects?

Student stu = new Student(); // Statement 1 student stu2// Statement 2 stu2 = new student()// Statement 3

String str1= null; STR1 = "C language Chinese network";

String str1;    // 相当于 String str1= null;
// 输出null字符串
System.out.println(str1);
// 调用length()方法
int len = str1.length();
// 判断对象是否为null
if (str1 != null) {
    int len = str1.length();
}
String str2 = "";
int num = str2.length();
System.out.println(num);    // 输出结果为0
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>