Open In App

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:

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


Article Tags :