Wednesday, May 6, 2026
HomeLanguagesJavaJava Guava | Floats.join() method with Examples

Java Guava | Floats.join() method with Examples

The join() method of Floats Class in the Guava library is used to combine or join all the given float values separated by a separator. These float 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 float values.

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

Syntax:

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

Parameters: This method accepts two mandatory parameters:

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

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

Below programs illustrate the use of this method:

Example 1:




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


Output:

2.3#4.2#6.2#8.6#10.5

Example 2:




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


Output:

3.2*5.4*7.6*9.1*11.2

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

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6887 POSTS0 COMMENTS
Nicole Veronica
12008 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12105 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7261 POSTS0 COMMENTS
Thapelo Manthata
6974 POSTS0 COMMENTS
Umr Jansen
6960 POSTS0 COMMENTS