package com.aff.equals; public class TestString { public static void main(String[] args) { String str1 = "AA"; String str2 = "AA"; String str3 = new String("AA"); System.out.println(str1 == str2);// true System.out.println(str1.equals(str2));// true System.out.println(str1 == str3);// false System.out.println(str1.equals(str3));// true; } }
输出结果:
true
true
false
true