Java == for String objects ceased to work?

前端 未结 11 1219
情深已故
情深已故 2021-01-02 04:13
  public class Comparison {
        public static void main(String[] args) {
            String s = \"prova\";
            String s2 = \"prova\";
            System.         


        
11条回答
  •  难免孤独
    2021-01-02 04:54

    You must understand that "==" compares references and "equals" compares values. Both s and s1 are pointing to the same string literal, so their references are the same.

提交回复
热议问题