Skip to content

Latest commit

 

History

History
32 lines (27 loc) · 845 Bytes

README.md

File metadata and controls

32 lines (27 loc) · 845 Bytes

目次 前の問題 次の問題


046:コアAPI:java.lang.String(2)

  • 次のプログラムをコンパイル・実行するとどうなるか?(実際に実行させずに解答すること)
public class Knock046 {
    public static void main(String[] arguments) {
        String s1 = "hoge";
        String s2 = "ho" + "ge";
        String s3 = new String(s1);
        String s4 = new String(s1).intern();
        printDifference(s1, s2);
        printDifference(s1, s3);
        printDifference(s1, s4);
    }
    
    private static void printDifference(String a, String b) {
        System.out.println(
              (a == b)
            + ":"
            + a.equals(b)
            + ":"
            + ((a.hashCode() == b.hashCode()))
        );
    }
}