Thursday, June 11, 2026
HomeLanguagesJavaJava Guava | Doubles.join() method with Examples

Java Guava | Doubles.join() method with Examples

The join() method of Doubles Class in the Guava library is used to combine or join all the given double values separated by a separator. These double values are passed a parameter to this method. This method also takes the separator as the parameter. This method returns a String which is the result of join operation on the specified double values.

For example: join(“-“, 1L, 2L, 3L) returns the string “1-2-3”.

Syntax:

public static String join(String separator, double… array)

Parameters: This method accepts two mandatory parameters:

  • separator: which is the doubleacter that occurs in between the joined double values.
  • array: which is an array of double values that are to be joined.

Return Value: This method returns a string containing all the given double values separated by separator.

Below programs illustrate the use of this method:

Example 1:




// Java code to show implementation of
// Guava's Doubles.join() method
  
import com.google.common.primitives.Doubles;
import java.util.Arrays;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating a double array
        double[] arr = { 2.3, 4.2, 6.2, 8.6, 10.5 };
  
        // Using Doubles.join() method to get a
        // string containing the elements of array
        // separated by a separator
        System.out.println(Doubles.join("#", arr));
    }
}


Output:

2.3#4.2#6.2#8.6#10.5

Example 2:




// Java code to show implementation of
// Guava's Doubles.join() method
  
import com.google.common.primitives.Doubles;
import java.util.Arrays;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating a double array
        double[] arr = { 3.2, 5.4, 7.6, 9.1, 11.2 };
  
        // Using Doubles.join() method to get a
        // string containing the elements of array
        // separated by a separator
        System.out.println(Doubles.join("*", arr));
    }
}


Output:

3.2*5.4*7.6*9.1*11.199999809265137

Reference: https://google.github.io/guava/releases/19.0/api/docs/com/google/common/primitives/Doubles.html#join(java.lang.String, %20double…)

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS