org.javatuples中的containsAll()方法用於檢查在TupleClass中是否存在作為參數給出的值的集合。此方法可用於javatuples庫的任何tuple類對象。根據TupleClass中該值集合的存在,它返回一個布爾值,該布爾值是true還是false。
方法聲明:
public final boolean containsAll(Object... value)
用法:
boolean result = TupleClassObject.containsAll(X value1, X value2, ...) OR boolean result = TupleClassObject.containsAll(X[] values)
參數:此方法將一個或多個值作為參數,其中:
- X-表示參數中值的數據類型。
- TupleClassObject-表示JavaTuple Class對象,例如Unit,Quintet,Decade等。
返回值:如果元組中存在參數值,則此方法返回true。否則返回假
以下示例程序旨在說明使用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<String> 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<String, String, String, String, String,
String, String, String, String, String>
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類一起使用。
相關用法
- Java TreeSet containsAll()用法及代碼示例
- Java Stack containsAll()用法及代碼示例
- Java Vector containsAll()用法及代碼示例
- Java CopyOnWriteArrayList containsAll()用法及代碼示例
- Java AbstractSet containsAll()用法及代碼示例
- Java CopyOnWriteArraySet containsAll()用法及代碼示例
- Java HashSet containsAll()用法及代碼示例
- Java Set containsAll()用法及代碼示例
- Java LinkedHashSet containsAll()用法及代碼示例
- Java List containsAll()用法及代碼示例
- Java SortedSet containsAll()用法及代碼示例
- Java AbstractCollection containsAll()用法及代碼示例
- Java JavaTuples add()用法及代碼示例
- Java JavaTuples with()用法及代碼示例
- Java JavaTuples contains()用法及代碼示例
注:本文由純淨天空篩選整理自RishabhPrabhu大神的英文原創作品 JavaTuples containsAll() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。