Guava 的Ints.concat()方法用於將作為參數傳遞的數組組合到單個數組中。此方法從每個提供的數組返回的值組合成一個數組。例如,concat(new int [] {a,b},new int [] {},new int [] {c}返回數組{a,b,c}。
用法:
public static int[] concat(int[]... arrays)
參數:此方法將數組作為參數,表示零個或多個int數組。
返回值:此方法按順序返回包含源數組中所有值的單個數組。
範例1:
// Java code to show implementation of
// Guava's Ints.concat() method
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating 2 Integer arrays
int[] arr1 = { 1, 2, 3, 4, 5 };
int[] arr2 = { 6, 2, 7, 0, 8 };
// Using Ints.concat() method to combine
// elements from both arrays into a single array
int[] res = Ints.concat(arr1, arr2);
// Displaying the single combined array
System.out.println("Combined Array:"
+ Arrays.toString(res));
}
}
輸出:
Combined Array:[1, 2, 3, 4, 5, 6, 2, 7, 0, 8]
範例2:
// Java code to show implementation of
// Guava's Ints.concat() method
import com.google.common.primitives.Ints;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating 4 Integer arrays
int[] arr1 = { 1, 2, 3 };
int[] arr2 = { 4, 5 };
int[] arr3 = { 6, 7, 8 };
int[] arr4 = { 9, 0 };
// Using Ints.concat() method to combine
// elements from both arrays into a single array
int[] res = Ints.concat(arr1, arr2, arr3, arr4);
// Displaying the single combined array
System.out.println("Combined Array:"
+ Arrays.toString(res));
}
}
輸出:
Combined Array:[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
相關用法
- Java Guava Ints min()用法及代碼示例
- Java Guava Ints max()用法及代碼示例
- Java Guava Ints contains()用法及代碼示例
- Java Guava Ints toArray()用法及代碼示例
- Java Guava Ints indexOf()用法及代碼示例
- Java Guava Ints lastIndexOf()用法及代碼示例
- Java Guava Ints join()用法及代碼示例
- Java Guava Ints asList()用法及代碼示例
- Java Guava Ints.hashCode()用法及代碼示例
- Java Guava Ints.compare()用法及代碼示例
- Java Ints.indexOf(int[] array, int[] target)用法及代碼示例
- Java Guava Booleans.concat()用法及代碼示例
- Java Guava Bytes.concat()用法及代碼示例
- Java Guava Doubles.concat()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Ints concat() function | Guava | Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。