最近我在 Java 中发现了一个数组声明,对我来说它是某种特定的。
String[] book = new String[9_999_999 + 1];
有人可以澄清如何正确阅读此声明吗?
最佳答案
JLS 说:
3.10.1. Integer Literals
Underscores are allowed as separators between digits that denote the integer.
Primitive Data types
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.
For instance, if your code contains numbers with many digits, you can use an underscore character to separate digits in groups of three, similar to how you would use a punctuation mark like a comma, or a space, as a separator.
The following example shows other ways you can use the underscore in numeric literals:
long creditCardNumber = 1234_5678_9012_3456L; long socialSecurityNumber = 999_99_9999L; float pi = 3.14_15F; long hexBytes = 0xFF_EC_DE_5E; long hexWords = 0xCAFE_BABE; long maxLong = 0x7fff_ffff_ffff_ffffL; byte nybbles = 0b0010_0101; long bytes = 0b11010010_01101001_10010100_10010010;
关于java - 具体数组大小声明。 java ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50523183/