Java Guava | Booleans.concat() method with Examples

The concat() method of Booleans Class in the Guava library is used to concatenate the values of many arrays into a single array. These boolean arrays to be concatenated are specified as parameters to this method.

For example: concat(new boolean[] {a, b}, new boolean[] {}, new boolean[] {c} returns the array {a, b, c}.

Syntax :



public static boolean[] concat(boolean[]... arrays)

Parameter: This method accepts arrays as parameter which is the boolean arrays to be concatenated by this method.

Return Value: This method returns a single boolean array which contains all the specified boolean array values in its original order.

Below programs illustrate the use of concat() method:

Example-1 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to show implementation of
// Guava's Booleans.concat() method
  
import com.google.common.primitives.Booleans;
import java.util.Arrays;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
  
        // Creating 2 Boolean arrays
        boolean[] arr1 = { true, false, true };
        boolean[] arr2 = { false, false, false, true };
  
        // Using Booleans.concat() method to combine
        // elements from both arrays into a single array
        boolean[] res = Booleans.concat(arr1, arr2);
  
        // Displaying the single combined array
        System.out.println(Arrays.toString(res));
    }
}

chevron_right


Output:

[true, false, true, false, false, false, true]

Example-2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to show implementation of
// Guava's Booleans.concat() method
  
import com.google.common.primitives.Booleans;
import java.util.Arrays;
  
class GFG {
  
    // Driver's code
    public static void main(String[] args)
    {
        // Creating 4 boolean arrays
        boolean[] arr1 = { true, false, false };
        boolean[] arr2 = { true, true };
        boolean[] arr3 = { false, false, false };
        boolean[] arr4 = { false, true };
  
        // Using Booleans.concat() method to combine
        // elements from both arrays into a single array
        boolean[] res
            = Booleans.concat(arr1, arr2, arr3, arr4);
  
        // Displaying the single combined array
        System.out.println(Arrays.toString(res));
    }
}

chevron_right


Output:

[true, false, false, true, true, false, false, false, false, true]

Reference: https://google.github.io/guava/releases/20.0/api/docs/com/google/common/primitives/Booleans.html#concat-boolean:A…-



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.