How do you compare characters in Java to see if they are equal?

In Java, you can use the equals() method to compare if two characters are equal. Here is an example:

char c1 = 'a';
char c2 = 'b';

if (c1 == c2) {
    System.out.println("字符相等");
} else {
    System.out.println("字符不相等");
}

You can use the == operator to compare if two characters are equal. If the two characters are equal, the result of the expression is true; otherwise, it is false.

Leave a Reply 0

Your email address will not be published. Required fields are marked *