How can I concatenate two arrays in Java?

后端 未结 30 1975
走了就别回头了
走了就别回头了 2020-11-21 06:05

I need to concatenate two String arrays in Java.

void f(String[] first, String[] second) {
    String[] both = ???
}

What is t

30条回答
  •  甜味超标
    2020-11-21 06:24

    You could try converting it into a Arraylist and use the addAll method then convert back to an array.

    List list = new ArrayList(Arrays.asList(first));
      list.addAll(Arrays.asList(second));
      String[] both = list.toArray();
    

提交回复
热议问题