Java Unit Tuple 的 contains() 方法
要搜尋 JavaTuples 中 Unit 類的值,請使用 contains() 方法。
讓我們首先看看使用 JavaTuples 需要滿足哪些條件。要使用 JavaTuples 中的 Unit 類,您需要匯入以下包 −
import org.javatuples.Unit;
注意 − 下載和執行 JavaTuples 程式的步驟如果您使用 Eclipse IDE 在 Java Tuples 中執行 Unit 類,則右鍵單擊**Project → Properties → Java Build Path → Add External Jars**並上傳下載的 JavaTuples jar 檔案。
以下是示例 −
示例
import org.javatuples.Unit;
public class Demo {
public static void main(String[] args) {
Unit < String > u = Unit.with("Professional!");
// Search for an element
boolean valSearch = u.contains("Professional!");
System.out.println("Is the value in the Unit? " + valSearch);
}
}輸出
Is the value in the Unit? True
讓我們看另一個示例 −
import org.javatuples.Unit;
public class Demo {
public static void main(String[] args) {
Unit < String > u = Unit.with("Mobile!");
// Search for an element
boolean valSearch = u.contains("Desktop!");
System.out.println("Is the value in the Unit? " + valSearch);
}
}輸出
Is the value in the Unit? False
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP