Java 数组 newInstance() 方法

2025年3月20日 | 阅读时长1分钟

Array 类的 getInstance() 方法用于创建具有指定组件类型和维度的数组。如果 componentType 是非数组类或接口类型,则新数组将具有 dimensions.length 个维度,并且 componentType 是其组件类型。

语法

参数

componentType - 表示新数组组件类型的对象

dimensions - 一个 int 数组,表示新数组的维度

返回值

新数组

抛出

NullPointerException

IllegalArgumentException

ArrayIndexOutOfBoundsException -

NegativeArraySizeException

示例 1

输出

Array[0][0] = javaTpoint
Array[1][1] = .Net
Array[2][2] = c#

示例 2

输出

[0, 1, 2, 3]
下一主题Java 数组类