Help me on question 11/12Equality Operators


#1



Replace this line with your code.


#2

Hi @microjumper43264!

Can you be more specific?
In Java we have thesee equality operators:

== // equal
!= // not equal
>= // bigger or equal
<= // smaller or equal
> // bigger
< // smaller
! // just NOT (use it with boolean variables)

For strings or objects (string is object in fact) we have special equality operator ".equals".

public class Main {

    public static void main(String[] args) {
        String a = "Hi";
        String b = "Hi";
        System.out.println(a.equals(b)); // It's print "true"
        One one = new One();
        One one1 = new One();
        System.out.println(one.getClass().equals(one1.getClass())); // It's print "true" too
        System.out.println(one.equals(one1)); // It's print "false" because it's different objects
    }
}

class One {}

But remember that ".equals" is not null protected equality operator!


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.