如何在 Java 中创建 LabelValue 元组?


你可以使用 with() 方法或直接使用构造函数来创建一个 LabelValue 元组。我们首先来看看在使用 JavaTuples 之前你需要做什么。要使用 JavaTuples 中的 LabelValue 类,你需要导入以下包

import org.javatuples.LabelValue;

注意:下载 JavaTuples Jar 库来运行 JavaTuples 程序。如果你使用 Eclipse IDE,那么右键单击项目 -> 属性 -> Java 构建路径 -> 添加外部 Jar,然后上传下载的 JavaTuples jar 文件。请参阅以下指南,了解运行 JavaTuples 的所有步骤

步骤: 如何在 Eclipse 中运行 JavaTuples 程序

以下是创建 LabelValue JavaTuples 类并添加元素的一个示例

示例

import org.javatuples.LabelValue;
public class Demo {
   public static void main(String[] args) {
      LabelValue<Integer, Integer> lbValue = new LabelValue<Integer, Integer>(10, 100);
      System.out.println("Elements in the LabelValue Tuple = "+lbValue);
   }
}

输出

Elements in the LabelValue Tuple = [10, 100]
Above, we have created the LabelValue tuple with its 2 elements i.e. label and value:
LabelValue<Integer, Integer> lbValue = new LabelValue<Integer, Integer>(10, 100);

更新于: 30-7-2019

74 次浏览

开启你的职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.