Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka , Java - what does this "_" represent in integer literal [duplicate]

I come across the following syntax to represent an integer and it looks new to me. What does it signify

props.put(ProducerConfig.BATCH_SIZE_CONFIG, 16_384 * 4);

How does 16384 is different from 16_384 ?

like image 599
Nag Avatar asked Mar 04 '26 15:03

Nag


2 Answers

It's the same. You can use "_" on an integer to make it be more readable.

16_384 is more readable than 16384

16_384_000 is more readable than 16384000

like image 197
vinicius de novaes Avatar answered Mar 07 '26 05:03

vinicius de novaes


In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.

long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 999_99_9999L;

like image 45
Nag Avatar answered Mar 07 '26 04:03

Nag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!