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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

2.3#4.2#6.2#8.6#10.5

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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…)



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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.