A shorthand operator is a shorter way of expressing something that is already available in the Java programming language which leads to lesser lines of code. But, using shorthand operators & techniques reduces the code readability.
Table of Contents
- += operator
- Other Shorthand operators
- Ternary Operator
- Shorthand variable declaration
- Other Related Concepts
+= operatorThis is used for adding two values. Let us first look at the long-hand format using an example and then use the shorthand alternative.
In the above example, we used x += y instead of using x = x + y. Although both of these do the same exact thing which is to assign the sum of x & y to x.
Other Shorthand operators
Ternary OperatorUsing this operator, we could write the if..else statement in a single line. Let us look at both longhand and shorthand versions.
Shorthand variable declarationUsing the below shorthand technique, we could declare multiple variables in a single line. Let us take a look at the longhand and shorthand versions with an example.