标签:equal 内存 color 相同 字符串 pack obj 变量 包含
package Test; public class Solution { public static void main(String[] args) { String s1,s2,s3 = "abc", s4 ="abc" ; s1 = new String("abc"); s2 = new String("abc"); System.out.println("s1==s2:"+(s1==s2)); System.out.println("s1==s3:"+(s1==s3)); System.out.println("s3==s4:"+(s3==s4)); System.out.println("s1.equals(s2):"+(s1.equals(s2))); System.out.println("s1.equals(s3):"+(s1.equals(s3))); System.out.println("s3.equals(s4):"+(s3.equals(s4))); } }
注意:
StringBuffer s1 = new StringBuffer("a"); StringBuffer s2 = new StringBuffer("a"); System.out.println("s1.equals(s2):"+(s1.equals(s2)));//结果为false
标签:equal 内存 color 相同 字符串 pack obj 变量 包含
原文地址:https://www.cnblogs.com/zsgbmyblog/p/12684409.html