首页 青云排行榜 知识中心 控制台

该程序的输出结果是什么?(     )

 public class Test {
    public static void main (String args[]) {
        String a, b, c, d;
        a = "Hello1234";
        b = "Hello" + String.valueOf(1234);
        c = "Hello" + "1234";
        d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
        System.out.print (a == b);
        System.out.print (" ");
        System.out.print (a.equals(b));
        System.out.print (" ");
        System.out.print (a == c);
        System.out.print (" ");
        System.out.print (a.equals(c));
        System.out.print (" ");
        System.out.print (a == d);
        System.out.print (" ");
        System.out.print (a.equals(d));
        System.out.print (" ");
    }
 }

true true true true false true

false true true true false false

false true true true false true

false false true true false true

在 Java 中,每当我们使用双引号创建一个字符串时,Java 虚拟机会先在字符串常量池中查找是否存在该字符串,如果存在则直接返回常量池中的对象引用;如果不存在,则在常量池中创建该字符串,并返回对象引用。这样做的好处是避免了重复创建多个相同的字符串对象,减少了内存的开销。
关于我们
公司简介
联系我们
联系我们
售前咨询: leizhongnan@eval100.com
售后服务: 0755-26415932
商务合作: support@eval100.com
友情链接
金蝶软件
快递100
关注我们
Copyright © 2023-2023 深圳慧题科技有限公司 粤ICP备2023109746号-1 粤公网安备44030002001082