Guava – Booleans.concat()方法及示例
Guava库中布尔类的concat()方法是用来将许多数组的值连接成一个单一的数组。这些要串联的布尔数组被指定为该方法的参数。
例如:concat(new boolean[] {a, b}, new boolean[] {}, new boolean[] {c} 返回数组{a, b, c}。
语法:
public static boolean[] concat(boolean[]... arrays)
参数: 该方法接受数组作为参数,该数组是要被该方法连接的布尔数组。
返回值: 该方法返回一个布尔数组,其中包含所有指定的布尔数组值的原始顺序。
下面的程序说明了concat()方法的使用。
例子-1 :
// 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)); }}
输出:
[true, false, true, false, false, false, true]
例2 :
// 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)); }}
输出:
[true, false, false, true, true, false, false, false, false, true]
参考资料:
https://google.github.io/guava/releases/20.0/api/docs/com/google/common/primitives/Booleans.html#concat-boolean:A…-
