Conversion of collection to int array
for (Integer value : c) {
int i = value.intValue();
//do something with either value or i
}
Assuming the values are of type Integer
, you can try this:
Collection c = Sort.values();
Integer[] a = (Integer[])(c.toArray(new Integer[c.size()]));
Simply:
Integer[] yourArrayVar = yourCollectionVar.toArray(new Integer[0]);
java just needs to know what kind of array to produce.
The question was: conversion to int arrayInteger[]
can not be assigned to int[]
or vice versa
int[] array = c.stream().mapToInt( i -> i ).toArray();