Array setLong() method in Java Last Updated : 10 Nov, 2022 Comments Improve Suggest changes Like Article Like Report The java.lang.reflect.Array.setLong() is an inbuilt method in Java and is used to set a specified long value to a specified index of a given object array. Syntax: Array.setLong(Object []array, int index, long value) Parameter: 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 long value that is to be set at the given index of the given array. Return type: This is a void type method which doesn't returns any value. The update reflects upon the Object array passed as the argument. 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 programs illustrate the Array.setLong() method: Program 1 : Java // Java code to demonstrate setLong() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining long array long b[] = { 1, 2, 3, 4 }; System.out.print("Before Set : "); // printing the array for (long x : b) { System.out.print(x + " "); } long value = 10; // setLong method of class Array Array.setLong(b, 1, value); System.out.print("\nAfter Set : "); // printing array for (Long 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 setLong() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining long array to null long b[] = null; try { Array.setLong(b, 5, 10); } 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 setLong() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining long array long b[] = { 1, 2, 3, 4 }; try { Array.setLong(b, 5, 10); } 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 setLong() method of Array class import java.lang.reflect.Array; public class GfG { // main method public static void main(String[] args) { // Declaring and defining long variable long b = 1; try { Array.setLong(b, 5, 10); } 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 setLong() method in Java S ShivamKD Follow Improve Article Tags : Java Java - util package java-reflection-array java-lang-reflect-package Practice Tags : Java Similar Reads Array setShort() method in Java 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 Objec 3 min read Array getLong() Method in Java The java.lang.reflect.Array.getLong() is an inbuilt method in Java and is used to return an element at the given index from a specified Array as a long. Syntax: Array.getLong(Object []array, int index) Parameters : This method accepts two mandatory parameters: array: The object array whose index is 3 min read Array getShort() method in Java The java.lang.reflect.Array.getShort() is an in-built method of Array class in Java and is used to return the element present at a given index from the specified Array as a short. Syntax: Array.getShort(Object []array,int index) Parameters: array: The object array whose index is to be returned. inde 3 min read Field setLong() method in Java with Examples setLong() method of java.lang.reflect.Field used to set the value of a field as a long on the specified object. When you need to set the value of a field of an object as long then you can use this method to set value over an Object. Syntax: public void setLong(Object obj, long l) throws IllegalArgum 3 min read LongBuffer hasArray() method in Java The array() method of java.nio.LongBuffer Class is used to Return the Long array that backs this buffer. Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa. Invoke() the hasArray() method are used before invoking this method in order to ensu 2 min read Month getLong() method in Java The getLong() method is a built-in method of the Month ENUM which is used to get the value of the specified temporal field from this month instance as a long. Syntax: public long getLong(TemporalField field) Parameters: This method accepts a single parameter field whose long representation will be r 1 min read Random nextLong() method in Java with Examples The nextGaussian() method of Random class returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. Syntax: public long nextLong() Parameters: The function does not accepts any parameter. Return Value: This method returns the next pseudorandom, uni 1 min read Scanner nextLong() method in Java with Examples The nextLong(radix) method of java.util.Scanner class scans the next token of the input as a long. If the translation is successful, the scanner advances past the input that matched. If the parameter radix is not passed, then it behaves similarly as nextLong(radix) where the radix is assumed to be t 5 min read How to Find Length or Size of an Array in Java? Finding the length of an array is a very common and basic task in Java programming. Knowing the size of an array is essential so that we can perform certain operations. In this article, we will discuss multiple ways to find the length or size of an array in Java.In this article, we will learn:How to 3 min read AtomicLongArray toString() method in Java with Examples The Java.util.concurrent.atomic.AtomicLongArray.toString() is an inbuilt method in Java that returns a string that textually represents the current values of the AtomicLongArray. The resulting string is a concise and informative representation that is easy for a person to read. It is used to easily 2 min read Like