Guava – Shorts.concat()方法及实例
Shorts.concat() 是Guava库中Shorts类的一个方法,用于将多个数组的值连接成一个数组。 例如,concat(new short[] {a, b}, new short[] {}, new short[] {c} 返回数组{a, b, c}。
语法:
public static short[] concat(short[]... arrays)
这里,数组代表零个或多个短数组。
返回值: 一个单一的数组,包含源数组的所有值,按顺序排列。
例子-1。
// Java code to show implementation of// Guava's Shorts.concat() methodimport com.google.common.primitives.Shorts;import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating 2 short arrays short[] arr1 = { 1, 2, 3, 4, 5 }; short[] arr2 = { 6, 2, 7, 0, 8 }; // Using Shorts.concat() method to combine // elements from both arrays into a single array short[] res = Shorts.concat(arr1, arr2); // Displaying the single combined array System.out.println(Arrays.toString(res)); }}
输出:
[1, 2, 3, 4, 5, 6, 2, 7, 0, 8]
例子-2。
// Java code to show implementation of// Guava's Shorts.concat() methodimport com.google.common.primitives.Shorts;import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating 4 short arrays short[] arr1 = { 1, 2, 3 }; short[] arr2 = { 4, 5 }; short[] arr3 = { 6, 7, 8 }; short[] arr4 = { 9, 0 }; // Using Shorts.concat() method to combine // elements from both arrays into a single array short[] res = Shorts.concat(arr1, arr2, arr3, arr4); // Displaying the single combined array System.out.println(Arrays.toString(res)); }}
输出:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
参考资料:
https://google.github.io/guava/releases/23.0/api/docs/com/google/common/primitives/Shorts.html#concat-short:A…-
