Algo.Java.ConversionTips

Java. List to int[] and backwards

example

int[] example1 = list.stream().mapToInt(i->i).toArray();
// OR
int[] example2 = list.stream().mapToInt(Integer::intValue).toArray();

int [] ints = list.stream().mapToInt(Integer::intValue).toArray();

backwards

int[] intArray = {1, 2, 3, 4};
Integer[] integerArray = Arrays.stream(intArray)
                               .boxed()
                               .toArray(Integer[]::new);

conversion from map to array

Map.Entry<Integer, Integer>[] entriesArray =
                (Map.Entry<Integer, Integer>[]) map.entrySet().toArray(new Map.Entry<?, ?>[map.size()]);
This entry was posted in Без рубрики. Bookmark the permalink.