在Java中使用JavaTuples实现Pair 类和Unit 类
以下是在Java中从Unit类实现Pair类的示例-
示例
import org.javatuples.Unit;
import org.javatuples.Pair;
public class MyDemo {
public static void main(String[] args) {
Unit<String> unit = Unit.with("Tutorial");
System.out.println("单元类元素: " + unit);
Pair<String, String> pair = unit.addAt0("Learning");
System.out.println("Pair (Implemented from Unit Tuple): " + pair);
}
}输出结果
单元类元素: [Tutorial] Pair (Implemented from Unit): [Learning, Tutorial]
让我们看看另一个示例,其中我们将通过Unit类实现Pair类-
示例
import org.javatuples.Unit;
import org.javatuples.Pair;
public class MyDemo {
public static void main(String[] args) {
Unit<String> unit = Unit.with("Tutorial");
System.out.println("Unit class element = " + unit);
Pair<String, String> pair = unit.addAt1("Learning");
System.out.println("Pair Class (Implemented from Unit Tuple) = " + pair);
}
}输出结果
Unit class element = [Tutorial] Pair Class (Implemented from Unit Tuple) = [Tutorial, Learning]
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短