0

I want to convert the following ArrayList of Integer type to array of type int in java

ArrayList<Integer> arrlist = new ArrayList<Integer>(5);  
arrlist.add(10);  
arrlist.add(20);  
arrlist.add(30);  
arrlist.add(40);

Output:

[10, 20, 30, 40]
2
  • 2
    int[] array = arrList.stream().mapToInt(i -> i).toArray(); Commented Sep 6, 2023 at 17:06
  • 1
    Consider utilizing Integer arrays when converting to and from Collection objects. Commented Sep 6, 2023 at 17:55

1 Answer 1

2
int[] intArray = arrlist.stream()
                .mapToInt(Integer::intValue)
                .toArray();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.