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

后端 未结 5 2019
春和景丽
春和景丽 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:44

    If you have access to the Apache lang library, then you can use the ArrayUtils.toPrimitive(Integer[]) method like this:

    int[] primitiveArray = ArrayUtils.toPrimitive(objectArray);

提交回复
热议问题