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

更新於: 30-07-2019

147 瀏覽量

開啟您的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.