在 Java Decade Tuple 中搜索值


要在 Java Decade Tuple 中搜索值,請使用 contains() 方法。該方法返回布林值,即如果存在元素,則為 TRUE,否則,則為 FALSE。

讓我們先看看使用 JavaTuples 需要什麼。要在 JavaTuples 中使用 Decade 類,你需要匯入以下包

import org.javatuples.Decade;

注意 下載 JavaTuples Jar 庫以執行 JavaTuples 程式。如果使用 Eclipse IDE,則右鍵單擊專案 -> 屬性 -> Java 構建路徑 -> 新增外部 Jar,並上傳下載的 JavaTuples jar 檔案。參考以下指南瞭解執行 JavaTuples 的所有步驟

步驟如何在 Eclipse 中執行 JavaTuples 程式

以下是在 Java Decade Tuple 中搜索值的示例

示例

import org.javatuples.Decade;
public class Demo {
   public static void main(String[] args) {
      // Tuple with 10 elements
      Decade<String, String, String, String, String, String, String, String, String, String> d =
         Decade.with("AB","CD", "EF","GH", "IJ","KL", "MN","OP", "QR", "ST");
      System.out.println("Elements in the Decade Tuple = "+d);
      boolean res = d.contains("MN");
      System.out.println("Does the value exist in the Decade Tuple? = "+res);
   }
}

輸出

Elements in the Decade Tuple = [AB, CD, EF, GH, IJ, KL, MN, OP, QR, ST]
Does the value exist in the Decade Tuple? = true

更新於: 30-Jul-2019

79 次閱讀

開啟您的職業生涯

完成課程認證

開始
廣告
© . All rights reserved.