當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java Guava Doubles.concat()用法及代碼示例


Guava庫中Doubles類的concat()方法用於將許多數組的值連接到一個數組中。這些要串聯的雙精度數組被指定為此方法的參數。

For example: concat(new double[] {a, b}, new double[] {}, new double[] {c}
returns the array {a, b, c}.

用法:


public static double[] concat(double[]... arrays)

參數:此方法接受數組作為參數,該數組是此方法要連接的雙精度數組。

返回值:此方法返回單個double數組,該數組按其原始順序包含所有指定的double數組值。

以下示例程序旨在說明concat()方法的使用:

範例1:

// Java code to show implementation of 
// Guava's Doubles.concat() method 
  
import com.google.common.primitives.Doubles; 
import java.util.Arrays; 
  
class GFG { 
  
    // Driver's code 
    public static void main(String[] args) 
    { 
        // Creating 2 Double arrays 
        double[] arr1 = { 1.2, 2.3, 3.5, 4.4, 5.1 }; 
        double[] arr2 = { 6.2, 2.1, 7.2, 0.4, 8.7 }; 
  
        // Using Doubles.concat() method to combine 
        // elements from both arrays into a single array 
        double[] res = Doubles.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 Doubles.concat() method 
  
import com.google.common.primitives.Doubles; 
import java.util.Arrays; 
  
class GFG { 
  
    // Driver's code 
    public static void main(String[] args) 
    { 
        // Creating 4 Double arrays 
        double[] arr1 = { 1.2, 2.3, 3.4 }; 
        double[] arr2 = { 4.5, 5.6 }; 
        double[] arr3 = { 6.4, 7.6, 8.7 }; 
        double[] arr4 = { 9.7, 0.8 }; 
  
        // Using Doubles.concat() method to combine 
        // elements from both arrays into a single array 
        double[] res 
            = Doubles.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]

參考: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/primitives/Doubles.html#concat(double[]…)



相關用法


注:本文由純淨天空篩選整理自Sahil_Bansall大神的英文原創作品 Java Guava | Doubles.concat() method with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。