Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Ints toArray() function in Java
The toArray() method of the Ints class returns an array containing each value of collection, converted to a int value in the manner of Number.intValue(). Following is the syntax −
public static int[] toArray(Collection extends Number> collection)
Here, the parameter is the collection of Number instances
Let us first see an example −
Example
import java.util.Arrays;
import java.util.List;
import com.google.common.primitives.Ints;
class Demo {
public static void main(String[] args) {
List list = Arrays.asList(20, 40, 60, 80, 100, 120, 140, 160);
System.out.println("List = "+list);
int[] myArr = Ints.toArray(list);
System.out.println("Array (from list) = " + Arrays.toString(myArr));
}
}
Output
List = [20, 40, 60, 80, 100, 120, 140, 160] Array = [20, 40, 60, 80, 100, 120, 140, 160]
Advertisements
