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

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

    Using Guava, you can do the following:

    int[] intArray = Ints.toArray(intList);
    

    If you're using Maven, add this dependency:

    
       com.google.guava
       guava
       18.0
    
    

提交回复
热议问题