Ints toArray() function | Guava | Java
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:
Array from given List: [1, 2, 3, 4, 5]
Example 2: To demonstrate NullPointerException
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.