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:
// 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]
Example-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]
Recommended Posts:
- Java.util.BitSet class methods in Java with Examples | Set 2
- Shadowing of static functions in Java
- How does default virtual behavior differ in C++ and Java ?
- How are Java objects stored in memory?
- How are parameters passed in Java?
- Are static local variables allowed in Java?
- final variables in Java
- Default constructor in Java
- Assigning values to static final variables in Java
- Comparison of Exception Handling in C++ and Java
- Does Java support goto?
- Arrays in Java
- Inheritance and constructors in Java
- More restrictive access to a derived class method in Java
- Comparison of static keyword in C++ and Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



