- public class Demo {
- public static void main(String[] args) {
- String s1 = "你好";//s1 = 0x2233
- String s2 = "你好";//s2 = 0x2233
- System.out.println("s1 == s2 : " + (s1 == s2));//true
- System.out.println("s1.equals(s2) : " + (s1.equals(s2)));//true
-
- String s3 = "你好";
- String s4 = new String("你好");
- System.out.println("s3 == s4 : " + (s3 == s4));//false
- System.out.println("s3.equals(s4) : " + (s3.equals(s4)));//true
-
- String s5 = new String ("你好");
- String s6 = new String("你好");
- System.out.println("s5 == s6 : " + (s5 == s6));//false
- System.out.println("s5.equals(s6) : " + (s5.equals(s6)));//true
-
- //---------------------------------------------------------------------//
- String s7 = "你好";
- String s8 = "java";
- String s9 = "你好java";
- String s10 = s7 + s8;
- String s11 = s7 + "java";
- String s12 = "你好" + s8;
- String s13 = "你好" + "java";//s13 = "你好java";
-
- System.out.println("s9 == s10 : " + (s9 == s10));//false
- System.out.println("s9 == s11 : " + (s9 == s11));//false
- System.out.println("s9 == s12 : " + (s9 == s12));//false
- System.out.println("s9 == s13 : " + (s9 == s13));//true
- }
- }
复制代码
|
|