Java Guava | Doubles.concat() method with Examples

The concat() method of Doubles Class in the Guava library is used to concatenate the values of many arrays into a single array. These double arrays to be concatenated are specified as parameters to this method.

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

Syntax:



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

Parameter: This method accepts arrays as parameter which is the double arrays to be concatenated by this method.

Return Value: This method returns a single double array which contains all the specified double array values in its original order.

Below programs illustrate the use of concat() method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

[1.2, 2.3, 3.5, 4.4, 5.1, 6.2, 2.1, 7.2, 0.4, 8.7]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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));
    }
}

chevron_right


Output:

[1.2, 2.3, 3.4, 4.5, 5.6, 6.4, 7.6, 8.7, 9.7, 0.8]

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



My Personal Notes arrow_drop_up

In love with a semicolon because sometimes i miss it so badly)

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.