0

Isn't it supposed to be true, since "00" is equal to "00"?

I also tried this:

public static void main(String[] args) {
        System.out.println(("00" == repeat("0",2)));
    }
    public static String repeat(String str, int n) {
        String output = "";
        for (int i = 0; i < n; i++) {
            output += str;
        }
        return output;

But it still prints false.

Instinct
  • 1
  • 2
  • You should use .equals in this situation. == compares object identity. – matt Oct 31 '21 at 08:46
  • In Java, `==` checks for object identity (is it the same object), not if two objects have the same value. You need to use `"00".equals(repeat("0",2))`, see the duplicate. – Mark Rotteveel Oct 31 '21 at 08:47

0 Answers0