When I relearned Java from the basics, I felt that there were many points that I had not understood so far, so I have summarized the learning contents so that I can look back on them later.
Unary operators, arithmetic operators, etc. Used for calculations and comparisons.
Both indicate AND (OR), but & and | evaluate the right side even if the left side is false.
instanceof It is used in the following form. (I wrote it just in case I didn't know it was an operator)
instanceof
str instanceof String;
Basic data types can be compared with ==, but equals () is used when comparing reference type values. (When comparing with ==, it will be compared whether the reference destination is the same.)
It is used as follows. If the conditional expression before? Is true, the expression on the left is executed, and if it is false, the expression on the right is executed.
Ternary operator
String str = "a" == null ? "is null" : "is not null";
Recommended Posts