How can I concatenate two arrays in Java?

后端 未结 30 2088
走了就别回头了
走了就别回头了 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:37

    This should be one-liner.

    public String [] concatenate (final String array1[], final String array2[])
    {
        return Stream.concat(Stream.of(array1), Stream.of(array2)).toArray(String[]::new);
    }
    

提交回复
热议问题