Converting 'ArrayList to 'String[]' in Java

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

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

16条回答
  •  名媛妹妹
    2020-11-22 02:40

    ArrayList arrayList = new ArrayList();
    Object[] objectList = arrayList.toArray();
    String[] stringArray =  Arrays.copyOf(objectList,objectList.length,String[].class);
    

    Using copyOf, ArrayList to arrays might be done also.

提交回复
热议问题