Selected Reading

Java - Unary Operators



Unary Operators in Java

Java unary operators need only one operand to perform any operation, and these operators modify the value of a variable based on the operation performed. These operators include increasing a value by 1, decreasing a value by 1, and negating an expression.

These operators work with numeric data types like int, float, double, and long. The most common unary operators are post-increment (x++) and post-decrement (x--), used for loop control.

List of Java Unary Operators

The following table lists the unary operators in Java:

Name Operator Description Example
Unary plus +

The unary plus operator indicates a positive value(numbers are positive without this, however).

x = 5;
y = +x;
// y=5
Unary minus -