Ints toArray() function | Guava | Java Last Updated : 15 Nov, 2018 Comments Improve Suggest changes Like Article Like Report Guava's Ints.toArray() returns an array containing each value of collection, converted to a int value in the manner of Number.intValue() Syntax: public static int[] toArray(Collection<? extends Number> collection) Parameters: This method takes the collection as parameter which is a collection of Number instances. Return Value: This method returns an array containing the same values as collection, in the same order, converted to primitives. Exceptions: This method throws NullPointerException if collection or any of its elements is null. Below examples illustrate the Ints.toArray() method: Example 1: Java // Java code to show implementation of // Guava's Ints.toArray() method import com.google.common.primitives.Ints; import java.util.Arrays; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Creating a List of Integers List<Integer> myList = Arrays.asList(1, 2, 3, 4, 5); // Using Ints.toArray() method to convert // a List or Set of Integer to an array // of Int int[] arr = Ints.toArray(myList); // Displaying an array containing each // value of collection, // converted to a int value System.out.println("Array from given List: " + Arrays.toString(arr)); } } Output: Array from given List: [1, 2, 3, 4, 5] Example 2: To demonstrate NullPointerException Java // Java code to show implementation of // Guava's Ints.toArray() method import com.google.common.primitives.Ints; import java.util.Arrays; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { try { // Creating a List of Integers List<Integer> myList = Arrays.asList(2, 4, null); // Using Ints.toArray() method to convert // a List or Set of Integer to an array // of Int. This should raise "NullPointerException" // as the collection contains "null" as an element int[] arr = Ints.toArray(myList); // Displaying an array containing each // value of collection, converted to a int value System.out.println(Arrays.toString(arr)); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.NullPointerException Reference: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/primitives/Ints.html#toArray-java.util.Collection- Comment More infoAdvertise with us Next Article Ints toArray() function | Guava | Java S Sahil_Bansall Follow Improve Article Tags : Java java-guava Practice Tags : Java Similar Reads Ints max() function | Guava | Java Guava's Ints.max() returns the greatest value present in array. Syntax: public static int max(int... array) Parameters: This method takes the array as parameter which is a nonempty array of int values. Return Value: This method returns the value present in array that is greater than or equal to ever 2 min read Ints min() function | Guava | Java Guava's Ints.min() returns the least value present in array. Syntax: public static int min(int... array) Parameters: This method takes the array as parameter which is a nonempty array of int values. Return Value: This method returns the value present in array that is lesser than or equal to every ot 2 min read Ints lastIndexOf() function | Guava | Java Guava's Ints.lastIndexOf() returns the index of the last appearance of the value target in array. Syntax: public static int lastIndexOf(int[] array, int target) Parameters: array: An array of int values, possibly empty. target: A primitive int value. Return Value: The Ints.indexOf() method returns t 2 min read Guava's Ints.join() Function in Java Ints.join() function provided by Guava library in Java for working with primitive integer arrays. It simplifies the process of converting an array of integers into a single concatenated string, with a specified delimiter separating the elements. For example, join("-", 1, 2, 3) returns the string "1- 2 min read Ints asList() function | Guava | Java Guava's Ints.asList() returns a fixed-size list backed by the specified array. Syntax: public static List<Integer> asList(int[] array) Parameters: This method takes the array as parameter which is the array to back the list. Return Value: This method returns a fixed-size list backed by the spe 2 min read Ints concat() function | Guava | Java Guava's Ints.concat() method is used to combine the arrays passed as parameters into a single array. This method returns the values from each provided array combined into a single array. For example, concat(new int[] {a, b}, new int[] {}, new int[] {c} returns the array {a, b, c}. Syntax: public sta 2 min read Ints indexOf() function | Guava | Java Guava's Ints.indexOf(int[] array, int target) method returns the index of the first appearance of the value target in array. Syntax: public static int indexOf(int[] array, int target) Parameters: This method accepts the following parameters: array: An array of int values, possibly empty. target: A p 2 min read Ints Class | Guava | Java Ints is a utility class for primitive type int. It provides Static utility methods pertaining to int primitives, that are not already found in either Integer or Arrays. Declaration : @GwtCompatible(emulated=true) public final class Ints extends Object Below table shows the Field summary for Guava In 3 min read Java Collection toArray() Method The toArray() method of Java Collection returns an array containing elements that are inside the calling collection. This article will discuss the toArray() method, its syntaxes, how it works, and some code examples. Syntax of toArray() MethodObject[] toArray();Return Type: The return type of the ab 3 min read Set toArray() Method in Java In Java, the toArray() method is used to convert a collection to an array. It returns an array containing all the elements in the collection in the correct order.Example 1: Converting a Set to an ArrayThis is an example where a Set of String elements is converted into an array using the toArray() me 2 min read Like