The equality operator (==) in Java is used to check if two values are equal. It returns true if the values are equal and false otherwise.
public class EqualityOperatorExample {
public static void main(String[] args) {
// Example values
int number1 = 5;
int number2 = 7;
// Check if the values are equal
if (number1 == number2) {
System.out.println("The values are equal.");
} else {
System.out.println("The values are not equal.");
}
}
}
In this example, number1
and number2
are compared using the equality operator (==
). If the values are equal, it prints "The values are equal"; otherwise, it prints "The values are not equal."