Guava庫中Floats類的concat()方法用於將許多數組的值連接到一個數組中。這些要連接的float數組被指定為此方法的參數。
For example: concat(new float[] {a, b}, new float[] {}, new float[] {c} returns the array {a, b, c}.
用法:
public static float[] concat(float[]... arrays)
參數:此方法接受數組作為參數,該數組是此方法要連接的float數組。
返回值:此方法返回一個單個float數組,該數組按原始順序包含所有指定的float數組值。
以下示例程序旨在說明concat()方法的使用:
範例1:
// Java code to show implementation of
// Guava's Floats.concat() method
import com.google.common.primitives.Floats;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating 2 Float arrays
float[] arr1 = { 1.2f, 2.3f, 3.5f, 4.4f, 5.1f };
float[] arr2 = { 6.2f, 2.1f, 7.2f, 0.4f, 8.7f };
// Using Floats.concat() method to combine
// elements from both arrays into a single array
float[] res = Floats.concat(arr1, arr2);
// Displaying the single combined array
System.out.println(Arrays.toString(res));
}
}
輸出:
[1.2, 2.3, 3.5, 4.4, 5.1, 6.2, 2.1, 7.2, 0.4, 8.7]
範例2:
// Java code to show implementation of
// Guava's Floats.concat() method
import com.google.common.primitives.Floats;
import java.util.Arrays;
class GFG {
// Driver's code
public static void main(String[] args)
{
// Creating 4 Float arrays
float[] arr1 = { 1.2f, 2.3f, 3.4f };
float[] arr2 = { 4.5f, 5.6f };
float[] arr3 = { 6.4f, 7.6f, 8.7f };
float[] arr4 = { 9.7f, 0.8f };
// Using Floats.concat() method to combine
// elements from both arrays into a single array
float[] res = Floats.concat(arr1, arr2, arr3, arr4);
// Displaying the single combined array
System.out.println(Arrays.toString(res));
}
}
輸出:
[1.2, 2.3, 3.4, 4.5, 5.6, 6.4, 7.6, 8.7, 9.7, 0.8]
相關用法
- Java Guava Doubles.min()用法及代碼示例
- Java Guava Doubles.contains()用法及代碼示例
- Java Guava Floats.contains()用法及代碼示例
- Java Guava Bytes.contains()用法及代碼示例
- Java Guava Longs.contains()用法及代碼示例
- Java Guava Shorts.min()用法及代碼示例
- Java Guava Longs.min()用法及代碼示例
- Java Guava Chars.min()用法及代碼示例
- Java Guava Floats.min()用法及代碼示例
- Java Guava Longs.max()用法及代碼示例
- Java Guava Doubles.max()用法及代碼示例
- Java Guava Chars.max()用法及代碼示例
- Java Guava Floats.max()用法及代碼示例
- Java Guava Booleans.contains()用法及代碼示例
- Java Guava Shorts.contains()用法及代碼示例
注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Java Guava | Floats.concat() method with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。