Answers for "list method to convert arraylist into on integer"

2

convert int array to integer list java

int[] arr = {1,2,3};
IntStream.of(arr).boxed().collect(Collectors.toList());
Posted by: Guest on May-22-2020
0

arraylist to int array conversion in java

//use this if you don't want to use any methods to convert an
//arrayList(with the same size as required array) to a 'int[]' type.
//Also, this is only useful when you know the size of the array you're working with.

  int[] array = new int[size];
  for (int i = 0; i < array.length; i++) {
      ans[i] = arraylist.get(i);
  }
// array will be now of int[] type

// Also as @FineFinch pointed it could be done using :
    //only works in java 8 or later
    list.stream().mapToInt(i -> i).toArray();
Posted by: Guest on August-20-2021

Code answers related to "list method to convert arraylist into on integer"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language