- java.lang.reflect Package Classes
- java.lang.reflect - Home
- java.lang.reflect - AccessibleObject
- java.lang.reflect - Array
- java.lang.reflect - Constructor<T>
- java.lang.reflect - Field
- java.lang.reflect - Method
- java.lang.reflect - Modifier
- java.lang.reflect - Proxy
- java.lang.reflect Package Extras
- java.lang.reflect - Interfaces
- java.lang.reflect - Exceptions
- java.lang.reflect - Error
- java.lang.reflect Useful Resources
- java.lang.reflect - Quick Guide
- java.lang.reflect - Useful Resources
- java.lang.reflect - Discussion
java.lang.reflect.Array.setShort() Method Example
Description
The java.lang.reflect.Array.setShort(Object array, int index, short value) method sets the value of the indexed component of the specified array object to the specified short value.
Declaration
Following is the declaration for java.lang.reflect.Array.setShort(Object array, int index, short value) method.
public static void setShort(Object array, int index, short value) throws IllegalArgumentException, ArrayIndexOutOfBoundsException
Parameters
array − the array.
index − the index.
value − the new value of the indexed component.
Exceptions
NullPointerException − If the specified object argument is null.
IllegalArgumentException − If the specified object argument is not an array, or if the array component type is primitive and an unwrapping conversion fails.
ArrayIndexOutOfBoundsException − If the specified index argument is negative, or if it is greater than or equal to the length of the specified array
Example
The following example shows the usage of java.lang.reflect.Array.setShort(Object array, int index, short value) method.
package com.tutorialspoint; import java.lang.reflect.Array; public class ArrayDemo { public static void main(String[] args) { short[] array = new short[]{1,2,3}; Array.setShort(array, 0, (short)2); Array.setShort(array, 1, (short)3); Array.setShort(array, 2, (short)4); System.out.println("array[0] = " + Array.getShort(array, 0)); System.out.println("array[1] = " + Array.getShort(array, 1)); System.out.println("array[2] = " + Array.getShort(array, 2)); } }
Let us compile and run the above program, this will produce the following result −
array[0] = 2 array[1] = 3 array[2] = 4