Questions mark is part of the ternary operator
?:
, that is a different version of the if
statementYou can use the ternary operator to select a value by some condition:
java.util.List<Integer> list = java.util.List.of(1, 2, 3);
String result = list.contains(2) ? "Two is in the list" : "Two is not in the list";
System.out.println(result); // Two is in the list