mark cerqueira well-rounded nerd

Underscores in Java Numbers

Following variable shadowing and catch-less try blocks, today we explore another cool little Java thing I learned about the other day: underscores in Java numeric literals.

// Declaring a few "numbers" with underscores to make them more readable
int oneMillion = 1_000_000;
long creditCardNumber = 1111_2222_3333_4444L;
long socialSecurityNumber = 111_222_3333L;

Unlike variable shadowing and catch-less try blocks, underscores in numeric literals makes things clearer and more readable so I encourage using them!

Read more about this handy little language feature and see more examples in the official Java documentation.