📜  JavaTuples containsAll() 方法

📅  最后修改于: 2022-05-13 01:55:41.390000             🧑  作者: Mango

JavaTuples containsAll() 方法

org.javatuples 中的containsAll()方法用于检查作为参数给出的 TupleClass 中是否存在值的集合。此方法可用于 javatuples 库的任何元组类对象。它根据 TupleClass 中是否存在该值集合返回一个布尔值,该值是真还是假。

方法声明:

public final boolean containsAll(Object... value)

句法:

boolean result = TupleClassObject.containsAll(X value1, X value2, ...)
                    OR
boolean result = TupleClassObject.containsAll(X[] values)

参数:此方法将一个或多个值作为参数,其中:

  • X – 表示参数中值的数据类型。
  • TupleClassObject – 表示使用的 JavaTuple 类对象,如 Unit、Quintet、Decade 等。

返回值:如果元组中存在参数值,则此方法返回 true。否则返回 false

下面的程序说明了使用 containsAll() 方法的各种方法:

程序 1:将 containsAll() 与 Unit 类一起使用:

// Below is a Java program to use containsAll() method
  
import java.util.*;
import org.javatuples.Unit;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating an Unit with one value
        Unit unit = Unit.with("GeeksforGeeks");
  
        // Using containsAll() method
  
        boolean res;
  
        // for True result
        String[] check = { "GeeksforGeeks" };
        res = unit.containsAll(check);
  
        System.out.println("Is " + Arrays.toString(check) + " present : " + res);
  
        // for False result
        String[] check1 = { "Geeks", "for", "Geeks" };
        res = unit.containsAll(check1);
  
        System.out.println("Is " + Arrays.toString(check1) + " present : " + res);
    }
}

输出:

Is [GeeksforGeeks] present : true
Is [Geeks, for, Geeks] present : false

程序 2:将 containsAll() 与 Decade 类一起使用:

// Below is a Java program to use containsAll() method
  
import java.util.*;
import org.javatuples.Decade;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating a Decade with 10 value
        Decade
            decade = Decade.with("Geeks",
                                 "for",
                                 "Geeks",
                                 "A",
                                 "Computer",
                                 "Science",
                                 "Portal",
                                 "for",
                                 "Geeks",
                                 "RishabhPrabhu");
  
        // Using containsAll() method
        boolean res;
  
        // for true result
        String[] check = { "Geeks", "for", "Geeks" };
        res = decade.containsAll(check);
  
        System.out.println("Is " + Arrays.toString(check) + " present : " + res);
  
        // for False result
        String[] check1 = { "Geeks", "not", "for", "Geeks" };
        res = decade.containsAll(check1);
  
        System.out.println("Is " + Arrays.toString(check1) + " present : " + res);
    }
}

输出:

Is [Geeks, for, Geeks] present : true
Is [Geeks, not, for, Geeks] present : false

注意:类似地,它可以与任何其他 JavaTuple 类一起使用。