Underscores in Numeric Literals

In this section, you will learn about how you can use underscore in Numeric Literals in Java SE 7.

Underscores in Numeric Literals

In this section, you will learn about how you can use underscore in Numeric
Literals in Java SE 7.

In Java SE 7, You can place any number of underscore( _ ) between
digits of numeric literals. This added feature improves the readability of the
code. For example : Using underscore you can separate groups of digits in
numeric literals . For Example credit card number can be write as follows :

long creditCardNumber = 1234_5678_9012_3456L;

You can place underscore between digits. But for placing underscore you need
to be careful. You can't place underscore in the following places :

You can't place it at the beginning or at the end of a number.

Adjacent to a decimal point in a floating point literal.

Before to an F or L suffix.

In positions where a string of digits is expected.

Some of the valid example with different type of data type is given below :