import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
class TesteArray {
public static void main
(String[] args
) { String[] arrayA
= {"A0",
"A1",
"A2",
"A3"}; String[] arrayB
= {"B0",
"B1",
"B2"};
// Primeira forma.
String[] arrayC1
= new String[arrayA.
length + arrayB.
length]; for (int i = 0; i < arrayA.length; i++) {
arrayC1[i] = arrayA[i];
}
for (int i = 0; i < arrayB.length; i++) {
arrayC1[i + arrayA.length] = arrayB[i];
}
// Segunda forma.
String[] arrayC2
= new String[arrayA.
length + arrayB.
length]; System.
arraycopy(arrayA,
0, arrayC2,
0, arrayA.
length); System.
arraycopy(arrayB,
0, arrayC2, arrayA.
length, arrayB.
length);
// Terceira forma.
List<String> lista = new ArrayList<>();
lista.
addAll(Arrays.
asList(arrayA
)); lista.
addAll(Arrays.
asList(arrayB
));
// Quarta forma.
String[] arrayC4
= Stream.
concat(Stream.
of(arrayA
), Stream.
of(arrayB
)).
toArray(String[]::new); }
}
aW1wb3J0IGphdmEudXRpbC5BcnJheUxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlzOwppbXBvcnQgamF2YS51dGlsLkxpc3Q7CmltcG9ydCBqYXZhLnV0aWwuc3RyZWFtLlN0cmVhbTsKCmNsYXNzIFRlc3RlQXJyYXkgewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFN0cmluZ1tdIGFycmF5QSA9IHsiQTAiLCAiQTEiLCAiQTIiLCAiQTMifTsKICAgICAgICBTdHJpbmdbXSBhcnJheUIgPSB7IkIwIiwgIkIxIiwgIkIyIn07CgogICAgICAgIC8vIFByaW1laXJhIGZvcm1hLgogICAgICAgIFN0cmluZ1tdIGFycmF5QzEgPSBuZXcgU3RyaW5nW2FycmF5QS5sZW5ndGggKyBhcnJheUIubGVuZ3RoXTsKICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGFycmF5QS5sZW5ndGg7IGkrKykgewogICAgICAgICAgICBhcnJheUMxW2ldID0gYXJyYXlBW2ldOwogICAgICAgIH0KICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IGFycmF5Qi5sZW5ndGg7IGkrKykgewogICAgICAgICAgICBhcnJheUMxW2kgKyBhcnJheUEubGVuZ3RoXSA9IGFycmF5QltpXTsKICAgICAgICB9CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKEFycmF5cy50b1N0cmluZyhhcnJheUMxKSk7CgogICAgICAgIC8vIFNlZ3VuZGEgZm9ybWEuCiAgICAgICAgU3RyaW5nW10gYXJyYXlDMiA9IG5ldyBTdHJpbmdbYXJyYXlBLmxlbmd0aCArIGFycmF5Qi5sZW5ndGhdOwogICAgICAgIFN5c3RlbS5hcnJheWNvcHkoYXJyYXlBLCAwLCBhcnJheUMyLCAwLCBhcnJheUEubGVuZ3RoKTsKICAgICAgICBTeXN0ZW0uYXJyYXljb3B5KGFycmF5QiwgMCwgYXJyYXlDMiwgYXJyYXlBLmxlbmd0aCwgYXJyYXlCLmxlbmd0aCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKEFycmF5cy50b1N0cmluZyhhcnJheUMyKSk7CgogICAgICAgIC8vIFRlcmNlaXJhIGZvcm1hLgogICAgICAgIExpc3Q8U3RyaW5nPiBsaXN0YSA9IG5ldyBBcnJheUxpc3Q8PigpOwogICAgICAgIGxpc3RhLmFkZEFsbChBcnJheXMuYXNMaXN0KGFycmF5QSkpOwogICAgICAgIGxpc3RhLmFkZEFsbChBcnJheXMuYXNMaXN0KGFycmF5QikpOwogICAgICAgIFN0cmluZ1tdIGFycmF5QzMgPSBsaXN0YS50b0FycmF5KG5ldyBTdHJpbmdbMF0pOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihBcnJheXMudG9TdHJpbmcoYXJyYXlDMykpOwoKICAgICAgICAvLyBRdWFydGEgZm9ybWEuCiAgICAgICAgU3RyaW5nW10gYXJyYXlDNCA9IFN0cmVhbS5jb25jYXQoU3RyZWFtLm9mKGFycmF5QSksIFN0cmVhbS5vZihhcnJheUIpKS50b0FycmF5KFN0cmluZ1tdOjpuZXcpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihBcnJheXMudG9TdHJpbmcoYXJyYXlDNCkpOwogICAgfQp9Cg==
[A0, A1, A2, A3, B0, B1, B2]
[A0, A1, A2, A3, B0, B1, B2]
[A0, A1, A2, A3, B0, B1, B2]
[A0, A1, A2, A3, B0, B1, B2]