3

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 ?

Nag
  • 1,818
  • 3
  • 24
  • 41
  • 2
    It's not, the underscore is allowed in Java numeric literals to increase readability. – daniu Jun 10 '20 at 11:49

2 Answers2

4

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

2

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;

Nag
  • 1,818
  • 3
  • 24
  • 41
  • 3
    Both are bad examples because they are not actually numbers, you cannot add, subtract, multiply or order credit card numbers from big to small, makes no sense. Both should be Strings instead. – luk2302 Jun 10 '20 at 12:09