ProAnswers.org

How to concatenate two String arrays in Java?

I need to concatenate two String arrays in Java.

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

What is the easiest way to do this?

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

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