• 常量池相关问题


    String常量池问题的几个例子
    示例1:
    Java代码
    String s0="kvill";
    String s1="kvill";
    String s2="kv" + "ill";
    System.out.println( s0==s1 );
    System.out.println( s0==s2 );
    结果为:
    true
    true
    示例2:
    示例:
    Java代码
    String s0="kvill";
    String s1=new String("kvill");
    String s2="kv" + new String("ill");
    System.out.println( s0==s1 );
    System.out.println( s0==s2 );
    System.out.println( s1==s2 );
    结果为:
    false
    false
    false
    示例3:
    Java代码
    String a = "a1";
    String b = "a" + 1;
    System.out.println((a == b)); //result = true
    String a = "atrue";
    String b = "a" + "true";
    System.out.println((a == b)); //result = true
    String a = "a3.4";
    String b = "a" + 3.4;
    System.out.println((a == b)); //result = true
    示例4:
    Java代码
    String a = "ab";
    String bb = "b";
    String b = "a" + bb;
    System.out.println((a == b)); //result = false
    示例5:
    Java代码
    String a = "ab";
    final String bb = "b";
    String b = "a" + bb;
    System.out.println((a == b)); //result = true
    示例6:
    Java代码
    String a = "ab";
    final String bb = getBB();
    String b = "a" + bb;
    System.out.println((a == b)); //result = false
    private static String getBB() {  return "b";   }
  • 相关阅读:
    Array.sort源码
    Linkedlist源码
    最大公约数 2.7
    腾讯笔试题
    腾讯2014校园招聘笔试题
    指针问题
    JavaScript 日历
    QT 初阶 第二章 创建对话框(查找对话框实例)
    QT 初阶 1.3 节 控件的几何排列
    “项目中的问题”
  • 原文地址:https://www.cnblogs.com/liuqing576598117/p/10600319.html
Copyright © 2020-2023  润新知