Java Guava | Booleans.join() method with Examples

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

For example: join(“-“, false, true, false) returns the string “false-true-false”.

Syntax:

public static String join(String separator,
                          boolean... array)

Parameters: This method accepts two mandatory parameters:

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

Return Value: This method returns a string containing all the given boolean 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 Booleans.join() method
  
import com.google.common.primitives.Booleans;
import java.util.Arrays;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
        // Creating a boolean array
        boolean[] arr = { true, false, true,
                          false, true };
  
        // Using Booleans.join() method to get a
        // string containing the elements of array
        // separated by a separator
        System.out.println(Booleans.join("#", arr));
    }
}

chevron_right


Output:

true#false#true#false#true

Example 2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

false*false*true*false

Reference: https://google.github.io/guava/releases/20.0/api/docs/com/google/common/primitives/Booleans.html#join-java.lang.String-boolean…-



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.