java – What is the underscore for in numeric literals?

Question:

What is the use of the underscore (_) in the situations below:

float pi =  3.14159_26535_89793_23846;
long bytes = 00101001_00100110_01100001;
int n = 1____________________1;

Answer:

It's just to make reading easier. The compiler ignores them. For example this:

private long milisegundosNoDia = 86_400_000;

It's easier to read (by a human) than this:

private long milisegundosNoDia = 86400000;
Scroll to Top