Add String to beginning of String array

前端 未结 9 1022
孤独总比滥情好
孤独总比滥情好 2021-01-01 09:44

Is it possible to add a string to beginning of String array without iterating the entire array.

9条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 09:57

    This is corrected version of solution proposed by @matteosilv:

    String[] myArray= {"hi","hi2"};
    List list = new LinkedList(Arrays.asList(myArray));
    list.add(0, "h3");
    myArray = list.toArray(new String[list.size()]);
    

提交回复
热议问题