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() method
import 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() method
import 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]
注:本文由纯净天空筛选整理自Sahil_Bansall大神的英文原创作品 Java Guava | Shorts.concat() method with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。