How can I concatenate two arrays in Java?

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

    I found a one-line solution from the good old Apache Commons Lang library.
    ArrayUtils.addAll(T[], T...)

    Code:

    String[] both = ArrayUtils.addAll(first, second);
    

提交回复
热议问题