How to convert Integer[] to int[] array in Java?

后端 未结 5 2033
春和景丽
春和景丽 2020-12-02 17:01

Is there a fancy way to cast an Integer array to an int array? (I don\'t want to iterate over each element; I\'m looking for an elegant and quick way to write it)

T

5条回答
  •  一个人的身影
    2020-12-02 17:36

    You can use Stream APIs of Java 8

    int[] intArray = Arrays.stream(array).mapToInt(Integer::intValue).toArray();
    

提交回复
热议问题