Home

Published

- 1 min read

java convert array to another type

img of java convert array to another type

The solution for this is noted below

java convert array to another type

Solution

   import java.util.Arrays;

int[] arr = {1, 2, 3, 4};

// convertions
Object[] a = Arrays.stream(arr).mapToObj(i -> i).toArray();
Double[] b = Arrays.stream(arr).mapToDouble(i -> i).toArray();
Long[] c = Arrays.stream(arr).mapToLong(i -> i).toArray();

Try other methods by searching on the site. That is if this doesn’t work