How can I concatenate two arrays in Java?

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

    The Functional Java library has an array wrapper class that equips arrays with handy methods like concatenation.

    import static fj.data.Array.array;
    

    ...and then

    Array both = array(first).append(array(second));
    

    To get the unwrapped array back out, call

    String[] s = both.array();
    

提交回复
热议问题