I need to convert:

ArrayList<Double> list = new ArrayList<Double>(); 

in int[] arr;

Thank you in advance!

  • 3
    list.toArray(...) . - post_zeew
  • one
    By the way, you want to convert floating-point numbers to integers. How do you imagine this? - post_zeew

2 answers 2

You can do, for example, like this:

 List<Double> list = new ArrayList<>(); Double[] array = list.toArray(new Double[list.size()]); 

If you want to convert int[] arr to int[] arr then you can go like this:

 int[] arr = new int[array.length]; for (int i = 0; i < array.length; i++) { arr[i] = (int) array[i]; } 
     ArrayList<Double> list = new ArrayList<Double>(); int[] ints = list.stream().mapToInt(i -> i.intValue()).toArray(); 

    Only consider that floating-point numbers will throw out an exception.

    • it is probably worth clarifying that stream is available only from java 8 - abbath0767