Tables
Operators | Precedence |
---|---|
postfix | expr++ expr– |
unary | ++expr –expr +expr -expr ~ ! |
multiplicative | * / % |
additive | + - |
shift | « » »> |
relational | < > ⇐ >= instanceof |
equality | == != |
bitwise AND | & |
bitwise exclusive OR | ^ |
bitwise inclusive OR | | |
logical AND | && |
logical OR | || |
conditional operator (ternary) | ? : |
assignment | = += -= *= /= %= &= ^= |= <<= >>= >>>= |
Equality
==
The == operator only compares two references- i.e. whether the two object references point to the same object. The equals function actually compares the two values for equality:
String
A string is by nature an array.
myString.equals("myWord");
null
a == b
a == null
a != b
a != null
Collection
myCollection.size() != 0
In
The Java language doesn't have a IN operator. You must implement it by using another logic.
String
String[] arr = { "Nico", "Fred" };
Set<String> names = new HashSet<String>(Arrays.asList(arr));
System.out.println(names.contains("Nico")); // true
System.out.println(names.contains("Eric")); // false
String s = "Today is Monday";
boolean hasCheese = s.contains("Monday");
Date
Set<Integer> weekendDay = new HashSet<>();
weekendDay.add(Calendar.SATURDAY);
weekendDay.add(Calendar.SUNDAY);
weekendDay.contains(calendar.get(Calendar.DAY_OF_WEEK));