獲取 Java 中 LabelValue 元組的大小
要獲取 Java 中 LabelValue 元組的大小,請使用 getSize() 方法。我們首先看看 JavaTuples 需要的條件。要在 JavaTuples 中處理 LabelValue 類,需要匯入以下包 −
import org.javatuples.LabelValue;
注意 − 下載 JavaTuples Jar 庫來執行 JavaTuples 程式。如果您使用的是 Eclipse IDE,則右鍵單擊 Project -> Properties -> Java Build Path -> Add External Jars,並上傳下載的 JavaTuples jar 檔案。以下指南中介紹了執行 JavaTuples 的所有步驟 −
步驟 − 如何在 Eclipse 中執行 JavaTuples 程式
下面是一個示例,展示如何在 Java 中向 LabelValue 元組新增值 −
示例
import org.javatuples.LabelValue; public class Demo { public static void main(String[] args) { LabelValue<Integer, String> lv = new LabelValue<Integer, String>(5, "Rank"); System.out.println("LabelValue Tuple = "+lv); System.out.println("Get the key = "+lv.getLabel()); System.out.println("Get the value = "+lv.getValue()); System.out.println("Get the size of the Tuple = "+lv.getSize()); } }
輸出
LabelValue Tuple = [5, Rank] Get the key = 5 Get the value = Rank Get the size of the Tuple = 2
廣告