- package com.itcast.stringtest2;
- public class Demo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- String s1 = "abc";
- String s2 = "abc";
-
- System.out.println(s1 == s2);//true
- System.out.println(s1.equals(s2));//true
-
- String s3 = new String("abc");
- String s4 = new String("abc");
- System.out.println(s3 == s4);//false
- System.out.println(s3.equals(s4));//true
-
- String s5 = "a";
- String s6 = "b";
- String s7 = "ab";
- // String s7 = "a" + "b";
-
- String s8 = s5 + s6;
- System.out.println("s7 == s8 : " + (s7 == s8));
- System.out.println("(s5 + s6) == s7 :" + ((s5 + s6) == s7));
- System.out.println("\"a\" + \"b\" == s7 : " + ("a" + "b" == s7));
- System.out.println("\"a\" + s6 == s7 : " + ("a" + s6 == s7));
- System.out.println("(s5 + \"b\" == s7 : " + (s5 + "b" == s7));
-
- String s9 = new String("abc");
- String s10 = "abc";
- System.out.println("s9 == s10 : " + (s9 == s10));
- System.out.println("s9.equals(s10) : " + (s9.equals(s10)));
-
-
-
-
-
-
- }
- }
复制代码
|
|