Java元组中的Pair类是什么?
JavaTuples中的Pair类只能包含2个元素。JavaTuples库包含Pair类。
以下是声明-
public final class Pair<P, Q> extends Tuple implements IValue0<P>, IValue1<Q>
首先让我们看看使用JavaTuples所需的工具。要在JavaTuples中使用Pair类,您需要导入以下包-
import org.javatuples.Pair;
它的一些功能包括-
类型安全
可序列化
可比
可迭代的
一成不变的
注-下载和运行JavaTuples程序的步骤如果使用EclipseIDE在JavaTuples中运行PairClass,则右键单击Project→Properties→JavaBuildPath→AddExternalJars并上传下载的JavaTuplesjar文件。
让我们看看如何在Java中创建一个对元组。以下是一个例子-
示例
import org.javatuples.Pair;
public class Demo {
public static void main(String[] args) {
Pair < String, String > p = new Pair("Chinese", "French");
System.out.println("Result = " + p);
}
}输出结果
Result = [Chinese, French]
热门推荐
10 生日寿宴祝福语简短精辟
11 姨父生日祝福语简短精辟
12 小朋友祝福语简短的话
13 中考祝福语简短高级句
14 新婚祝福语简短十六字
15 送菜的祝福语简短霸气
16 礼盒宝宝生日祝福语简短
17 毕业祝福语保安文案简短
18 贺卡祝福语宝宝男孩简短