提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
要查看两个String对象是否具有匹配的值,请使用该类的equals()方法。
//时代Java - N o w J a v a . c o m 提供 public class Main { public static void main(String[] arguments) { String str1, str2; str1 = "this is a test."; str2 = str1; System.out.println("String1: " + str1); System.out.println("String2: " + str2); System.out.println("Same object? " + (str1 == str2)); str2 = new String(str1); System.out.println("String1: " + str1); System.out.println("String2: " + str2); System.out.println(