是的,这可以在没有循环的情况下实现。使用ArrayUtils.addAll(T[], T...)
String[] both = ArrayUtils.addAll(image, image2);
这是一个数组到/从List 转换的解决方案。
String[] image = new String[] {"APP","FIELD","KYC"};
String[] image2 = new String[] {"MEMORANDUM","ASSOCIATION"};
List<String> list = new ArrayList<String>(Arrays.asList(image));
list.addAll(Arrays.asList(image2));
String[] result = list.toArray(new String[]{});
System.out.println(Arrays.toString(result));
输出将与您所要求的相同。
正如 Mena 建议的那样,另一种解决方案可以是 System.arraycopy
String[] image = new String[] {"APP","FIELD","KYC"};
String[] image2 = new String[] {"MEMORANDUM","ASSOCIATION"};
String[] result = new String[image.length + image2.length];
// copies an array from the specified source array
System.arraycopy(image, 0, result, 0, image.length);
System.arraycopy(image2, 0, result, image.length, image2.length);
// Now you can use result for final array
阅读更多关于How can I concatenate two arrays in Java?