以下是在Java中从Unit类实现Pair类的示例-
示例import org.javatuples.Unit;
import org.javatuples.Pair;
public class MyDemo {
public static void main(String[] args) {
Unit unit = Unit.with("Tutorial");
System.out.println("单元类元素: " + unit);
Pair 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 unit = Unit.with("Tutorial");
System.out.println("Unit class element = " + unit);
Pair 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]