0

I want to compare two strings in an instance of a class. I believe their contents are the same but it seems not so for java. In my understanding solution.a and solution.c should be both "abc" and I have verified so by print both out. Can anyone explain this to me?

main.java:

public class Main {
    public static void main(String[] args) {
        Solution test= new Test();
        if (test.a != test.c) {
            throw new RuntimeException();
        }
    }
}

test.java:

public class Test{
    String a = "abc";
    String b = "ab";
    String c = b + "c";
}

Running the above code will cause an RuntimeException.

0 Answers0