Ints concat() function | Guava | Java
Last Updated :
10 May, 2019
Guava’s Ints.concat() method is used to combine the arrays passed as parameters into a single array. This method returns the values from each provided array combined into a single array. For example, concat(new int[] {a, b}, new int[] {}, new int[] {c} returns the array {a, b, c}.
Syntax:
public static int[] concat(int[]... arrays)
Parameters: This method takes arrays as parameter which represents zero or more int arrays.
Return Value: This method returns a single array containing all the values from the source arrays, in order.
Example 1:
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
int [] arr1 = { 1 , 2 , 3 , 4 , 5 };
int [] arr2 = { 6 , 2 , 7 , 0 , 8 };
int [] res = Ints.concat(arr1, arr2);
System.out.println( "Combined Array: "
+ Arrays.toString(res));
}
}
|
Output:
Combined Array: [1, 2, 3, 4, 5, 6, 2, 7, 0, 8]
Example 2:
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
public static void main(String[] args)
{
int [] arr1 = { 1 , 2 , 3 };
int [] arr2 = { 4 , 5 };
int [] arr3 = { 6 , 7 , 8 };
int [] arr4 = { 9 , 0 };
int [] res = Ints.concat(arr1, arr2, arr3, arr4);
System.out.println( "Combined Array: "
+ Arrays.toString(res));
}
}
|
Output:
Combined Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Reference: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/primitives/Ints.html#concat-int:A…-
Share your thoughts in the comments
Please Login to comment...