java - 具体数组大小声明。 java

标签 java

最近我在 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.

Java Tutorial 说:

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/

相关文章:

Java - 如何让记录器在关闭 Hook 中工作?

java - 当出现null时如何用Stream过滤Map?

java - 比较枚举值

java - 带有请求响应 JSON 的 JD Edwards REST API

java - 每次测试前运行方法

Java - 无法打印图像(到纸张/打印机)

java - 比较数组内容精度算法

java - 使用 Spring MVC 在应用程序启动时执行 Java 类

java - 使用 @Query 在 intellij 中进行语言注入(inject)

java - 从 BaseAdapter 的 GridView 中检索 ArrayList 值