Array setShort() method in Java Last Updated : 25 Nov, 2022 Comments Improve Suggest changes Like Article Like Report The java.lang.reflect.Array.setShort() is an inbuilt method in Java and is used to set a specified short value to a specified index of a given object array. Syntax: Array.setShort(Object []array,int index, short value) Parameters: This method takes 3 parameters: array: This is an array of type Object which is to be updated. index: This is the index of the array which is to be updated. value: This is the short value that is to be set at the given index of the given array. Exception: This method throws following exceptions: NullPointerException– when the array is null. IllegalArgumentException – when the given object array is not an Array. ArrayIndexOutOfBoundsException – if the given index is not in the range of the size of the array. Below is the implementation of Array.setShort() method: Program 1 : Java // Java code to demonstrate // setShort() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining Short array short b[] = {1,2,3,4}; System.out.print("Before Set : "); // printing the array for(short x : b){ System.out.print(x + " "); } short value = 10; // set method of class Array Array.setShort(b, 1, value); System.out.print("\nAfter Set : "); // printing array for(short x : b){ System.out.print(x + " "); } } } Output: Before Set : 1 2 3 4 After Set : 1 10 3 4 Program 2 : to demonstrate java.lang.NullPointerException Java // Java code to demonstrate // setShort() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining Short array to null short b[] = null; try{ short s = 10; Array.setShort(b,5,s); } catch(Exception e){ System.out.println("Exception : " + e); } } } Output: Exception : java.lang.NullPointerException Program 3: To demonstrate java.lang.ArrayIndexOutOfBoundsException Java // Java code to demonstrate // setShort() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining Short array short b[] = {1,2,3,4}; try{ short s = 10; Array.setShort(b,5,s); } catch(Exception e){ System.out.println("Exception : " + e); } } } Output: Exception : java.lang.ArrayIndexOutOfBoundsException Program 4: To demonstrate java.lang.IllegalArgumentException Java // Java code to demonstrate // setShort() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining Short variable short b = 1; try{ short s = 10; Array.setShort(b,5,s); } catch(Exception e){ System.out.println("Exception : " + e); } } } Output: Exception : java.lang.IllegalArgumentException: Argument is not an array Comment More infoAdvertise with us Next Article Array setShort() method in Java S ShivamKD Follow Improve Article Tags : Misc Java Java-lang package Java-Arrays Java-Functions java-reflection-array java-lang-reflect-package +3 More Practice Tags : JavaMisc Similar Reads Array set() method in Java The java.lang.reflect.Array.set() is an inbuilt method in Java and is used to set a specified value to a specified index of a given object array. Syntax Array.set(Object []array, int index, Object value) Parameter : array : This is an array of type Object which is to be updated. index : This is the 3 min read Array setChar() method in Java The java.lang.reflect.Array.setChar() is an inbuilt method in Java and is used to change a specified char value to a specified index of a given object array. Syntax: Array.setChar(Object []array, int index, char value) Parameter: This method takes three parameters: array: This is an array of type Ob 3 min read Arrays.stream() Method in Java Arrays.stream() method is used to get a sequential Stream from the elements of an array passed as a parameter. Below is a simple example that uses Arrays.stream() to convert a String array into a Stream for sequential processing.Example:Java// Java program to demonstrate Arrays.stream() method impor 3 min read Java ArrayList set() Method The set() method of the ArrayList class in Java is used to replace an element at a specified position with a new value. This is very useful when we need to update an existing element in an ArrayList while maintaining the list's structure.Example 1: Here, we will use the set() method to update an ele 2 min read ArrayDeque spliterator() method in Java The spliterator() method of ArrayDeque returns a Spliterator of the same elements as ArrayDeque but created Spliterator is late-binding and fail-fast. A late-binding Spliterator binds to the source of elements means ArrayDeque at the point of first traversal, first split, or first query for estimate 2 min read ArrayDeque size() Method in Java The Java.util.ArrayDeque.size() method in Java is used to get the size of the Deque or the number of elements present in the Deque. Syntax: Array_Deque.size() Parameters: The method does not take any parameter. Return Value: The method returns the size or the number of elements present in the Deque. 2 min read ArrayDeque push() Method in Java The Java.util.ArrayDeque.push(E element) method is used to push an element into the Deque. The operation is similar to the operation in the stack. The element gets pushed onto the top of the deque. Syntax: Array_Deque.push(E element) Parameters: The parameter element is of the type ArrayDeque and re 2 min read Set to Array in Java Given a set (HashSet or TreeSet) of strings in Java, convert it into an array of strings. Input : Set hash_Set = new HashSet(); hash_Set.add("Geeks"); hash_Set.add("For"); Output : String arr[] = {"Geeks", "for"} Method 1 (Simple) We simply create an empty array. We traverse the given set and one by 3 min read Java ArrayList spliterator() Method The spliterator() method in Java is used to iterate over the elements of an ArrayList. It provides a more efficient way to traverse the collection specially with parallel processing. This method is part of Java 8 and later.Example 1: Here, we will use the spliterator() method to loop through element 3 min read ArrayDeque toArray() Method in Java The java.util.ArrayDeque.toArray() method is used to form an array of the same elements as that of the Deque. Basically, the method copies all the element from this deque to a new array. Syntax: Object[] arr = Array_Deque.toArray() Parameters: The method does not take any parameters. Return Value: T 2 min read Like