A. Instanceof operator:
The instanceof operator determines whether an object is a class instance.
Example:
class Main {
public static void main(String[] args) {
Integer number = 5;
boolean res;
if (res = number instanceof Integer){
System.out.println("number is an object of Integer. Hence: " + res);
} else {
System.out.println("number is not an object of Integer.Hence: " + res);
}
}
}
Output:
number is an object of Integer. Hence: true
B. Conditional operator:
A single-line if-else statement is used to apply a conditional operator.
Example:
class Main {
public static void main(String[] args) {
Integer number = 3;
String res;
res = (number > 5) ? "number greater than five" : "number lesser than five";
System.out.println(res);
}
}
Output:
number lesser than five