How can I concatenate two arrays in Java?

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

    Or with the beloved Guava:

    String[] both = ObjectArrays.concat(first, second, String.class);
    

    Also, there are versions for primitive arrays:

    • Booleans.concat(first, second)
    • Bytes.concat(first, second)
    • Chars.concat(first, second)
    • Doubles.concat(first, second)
    • Shorts.concat(first, second)
    • Ints.concat(first, second)
    • Longs.concat(first, second)
    • Floats.concat(first, second)

提交回复
热议问题