How to convert an ArrayList containing Integers to primitive int array?

前端 未结 18 1516
情书的邮戳
情书的邮戳 2020-11-22 11:23

I\'m trying to convert an ArrayList containing Integer objects to primitive int[] with the following piece of code, but it is throwing compile time error. Is it possible to

18条回答
  •  耶瑟儿~
    2020-11-22 11:53

    using Dollar should be quite simple:

    List list = $(5).toList(); // the list 0, 1, 2, 3, 4  
    int[] array = $($(list).toArray()).toIntArray();
    

    I'm planning to improve the DSL in order to remove the intermediate toArray() call

提交回复
热议问题