[Constant pool of strings]

package cn.itcast.day08.demo01;

/*
String constant pool; the double-quote string written directly in the program is in the string constant pool.

For basic types, == is for numerical comparison
For reference types, == is to compare address values
 */
public class Demo02StringPool {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "abc";

        char[] charArray = {'a','b','c'};
        String str3 = new String(charArray);

        System.out.println(str1==str2);
        System.out.println(str1==str3);
        System.out.println(str2==str3);
    }
}

Supongo que te gusta

Origin blog.csdn.net/m0_48114733/article/details/123290528
Recomendado
Clasificación