Java Guava | Shorts.concat() method with Examples
Shorts.concat() is a method of Shorts class in Guava library which is used to concatenate the values of multiple arrays into a single array. For example, concat(new short[] {a, b}, new short[] {}, new short[] {c} returns the array {a, b, c}.
Syntax :
public static short[] concat(short[]... arrays)
Here, arrays represent zero or more short arrays.
Return Value: A single array containing all the values from the source arrays, in order.
Example-1:
import com.google.common.primitives.Shorts;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
short [] arr1 = { 1 , 2 , 3 , 4 , 5 };
short [] arr2 = { 6 , 2 , 7 , 0 , 8 };
short [] res = Shorts.concat(arr1, arr2);
System.out.println(Arrays.toString(res));
}
}
|
Output:
[1, 2, 3, 4, 5, 6, 2, 7, 0, 8]
Example-2:
import com.google.common.primitives.Shorts;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
short [] arr1 = { 1 , 2 , 3 };
short [] arr2 = { 4 , 5 };
short [] arr3 = { 6 , 7 , 8 };
short [] arr4 = { 9 , 0 };
short [] res = Shorts.concat(arr1, arr2, arr3, arr4);
System.out.println(Arrays.toString(res));
}
}
|
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Reference: https://google.github.io/guava/releases/23.0/api/docs/com/google/common/primitives/Shorts.html#concat-short:A…-
Last Updated :
24 Jan, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...