Java Array newInstance() Method

The getInstance() method of Array class is used to create a new array with the specified component type and dimensions. If componentType is a class of type non-array or interface, the new array has dimensions.length dimensions and componentType as its component type.

Syntax

Parameter

componentType - the object representing the component type of the new array

dimensions - an array of int representing the dimensions of the new array

Returns

the new array

Throws

NullPointerException

IllegalArgumentException

ArrayIndexOutOfBoundsException -

NegativeArraySizeException

Example 1

Test it Now

Output:

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

Example 2

Test it Now

Output:

[0, 1, 2, 3]




Latest Courses