Array newinstance in java

Class Array

Array permits widening conversions to occur during a get or set operation, but throws an IllegalArgumentException if a narrowing conversion would occur.

Method Summary

Sets the value of the indexed component of the specified array object to the specified boolean value.

Methods declared in class java.lang.Object

Method Details

newInstance

Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:

int[] x = ; Array.newInstance(componentType, x);

newInstance

Creates a new array with the specified component type and dimensions. If componentType represents a non-array class or interface, the new array has dimensions.length dimensions and componentType as its component type. If componentType represents an array class, the number of dimensions of the new array is equal to the sum of dimensions.length and the number of dimensions of componentType . In this case, the component type of the new array is the component type of componentType . The number of dimensions of the new array must not exceed 255.

getLength

get

Returns the value of the indexed component in the specified array object. The value is automatically wrapped in an object if it has a primitive type.

getBoolean

getByte

getChar

getShort

getInt

getLong

getFloat

getDouble

set

Sets the value of the indexed component of the specified array object to the specified new value. The new value is first automatically unwrapped if the array has a primitive component type.

setBoolean

public static void setBoolean (Object array, int index, boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

Sets the value of the indexed component of the specified array object to the specified boolean value.

setByte

setChar

setShort

setInt

setLong

setFloat

setDouble

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Источник

Читайте также:  How to use different python versions

Class Array

Array permits widening conversions to occur during a get or set operation, but throws an IllegalArgumentException if a narrowing conversion would occur.

Method Summary

Sets the value of the indexed component of the specified array object to the specified boolean value.

Methods declared in class java.lang.Object

Method Details

newInstance

Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:

int[] x = ; Array.newInstance(componentType, x);

newInstance

Creates a new array with the specified component type and dimensions. If componentType represents a non-array class or interface, the new array has dimensions.length dimensions and componentType as its component type. If componentType represents an array class, the number of dimensions of the new array is equal to the sum of dimensions.length and the number of dimensions of componentType . In this case, the component type of the new array is the component type of componentType . The number of dimensions of the new array must not exceed 255.

getLength

get

Returns the value of the indexed component in the specified array object. The value is automatically wrapped in an object if it has a primitive type.

getBoolean

getByte

getChar

getShort

getInt

getLong

getFloat

getDouble

set

Sets the value of the indexed component of the specified array object to the specified new value. The new value is first automatically unwrapped if the array has a primitive component type.

setBoolean

public static void setBoolean (Object array, int index, boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

Sets the value of the indexed component of the specified array object to the specified boolean value.

setByte

setChar

setShort

setInt

setLong

setFloat

setDouble

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2023, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

Читайте также:  Java workspace in use

Источник

java.lang.reflect.Array.newInstance() Method Example

The java.lang.reflect.Array.newInstance(Class componentType, int length) method creates a new array with the specified component type and length.

Declaration

Following is the declaration for java.lang.reflect.Array.newInstance(Class componentType, int length) method.

public static Object newInstance(Class componentType, int length) throws IllegalArgumentException, NegativeArraySizeException

Parameters

  • componentType − the Class object representing the component type of the new array.
  • length − an array of int representing the dimensions of the new array.

Return Value

Exceptions

  • NullPointerException − If the specified componentType is null.
  • IllegalArgumentException − if the specified dimensions argument is a zero-dimensional array, or if the number of requested dimensions exceeds the limit on the number of array dimensions supported by the implementation (typically 255), or if componentType is Void.TYPE.
  • ArrayIndexOutOfBoundsException − If the specified index argument is negative.

Example

The following example shows the usage of java.lang.reflect.Array.newInstance(Class componentType, int length) method.

package com.tutorialspoint; import java.lang.reflect.Array; public class ArrayDemo < public static void main(String[] args) < String[] stringArray = (String[]) Array.newInstance(String.class, 3); Array.set(stringArray, 0, "Mahesh"); Array.set(stringArray, 1, "Ramesh"); Array.set(stringArray, 2, "Suresh"); System.out.println("stringArray[0] = " + Array.get(stringArray, 0)); System.out.println("stringArray[1] = " + Array.get(stringArray, 1)); System.out.println("stringArray[2] result notranslate">stringArray[0] = Mahesh stringArray[1] = Ramesh stringArray[2] = Suresh

Источник

Array newinstance in java

The Array class provides static methods to dynamically create and access Java arrays. Array permits widening conversions to occur during a get or set operation, but throws an IllegalArgumentException if a narrowing conversion would occur.

Method Summary

Sets the value of the indexed component of the specified array object to the specified boolean value.

Methods inherited from class java.lang.Object

Method Detail

newInstance

public static Object newInstance(Class componentType, int length) throws NegativeArraySizeException

Creates a new array with the specified component type and length. Invoking this method is equivalent to creating an array as follows:

int[] x = ; Array.newInstance(componentType, x);

newInstance

public static Object newInstance(Class componentType, int. dimensions) throws IllegalArgumentException, NegativeArraySizeException

Creates a new array with the specified component type and dimensions. If componentType represents a non-array class or interface, the new array has dimensions.length dimensions and componentType as its component type. If componentType represents an array class, the number of dimensions of the new array is equal to the sum of dimensions.length and the number of dimensions of componentType . In this case, the component type of the new array is the component type of componentType . The number of dimensions of the new array must not exceed 255.

Читайте также:  Что такое html определение

getLength

public static int getLength(Object array) throws IllegalArgumentException

get

public static Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

Returns the value of the indexed component in the specified array object. The value is automatically wrapped in an object if it has a primitive type.

getBoolean

public static boolean getBoolean(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getByte

public static byte getByte(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getChar

public static char getChar(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getShort

public static short getShort(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getInt

public static int getInt(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getLong

public static long getLong(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getFloat

public static float getFloat(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

getDouble

public static double getDouble(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

set

public static void set(Object array, int index, Object value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

Sets the value of the indexed component of the specified array object to the specified new value. The new value is first automatically unwrapped if the array has a primitive component type.

setBoolean

public static void setBoolean(Object array, int index, boolean z) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

Sets the value of the indexed component of the specified array object to the specified boolean value.

setByte

public static void setByte(Object array, int index, byte b) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

setChar

public static void setChar(Object array, int index, char c) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

setShort

public static void setShort(Object array, int index, short s) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

setInt

public static void setInt(Object array, int index, int i) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

setLong

public static void setLong(Object array, int index, long l) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

setFloat

public static void setFloat(Object array, int index, float f) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

setDouble

public static void setDouble(Object array, int index, double d) throws IllegalArgumentException, ArrayIndexOutOfBoundsException

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Источник

Оцените статью