Comparing strings in java

前端 未结 7 1482
别那么骄傲
别那么骄傲 2020-12-22 05:58
String string1 = \"Hi there\";
String string2 = \"Hi\";
String string3 = \"Hi\";

System.out.println(string1.substring(0, string2.length()) == string2); //1
System.o         


        
7条回答
  •  感情败类
    2020-12-22 06:40

    The == operator is checking if the two OBJECTS are equal (are they references to the same object), not comparing the values containes therein.

提交回复
热议问题