Converting 'ArrayList to 'String[]' in Java

前端 未结 16 1517
情书的邮戳
情书的邮戳 2020-11-22 01:59

How might I convert an ArrayList object to a String[] array in Java?

16条回答
  •  情话喂你
    2020-11-22 02:49

    An alternative in Java 8:

    String[] strings = list.stream().toArray(String[]::new);
    

    Java 11+:

    String[] strings = list.toArray(String[]::new);
    

提交回复
热议问题