以下是从Java中的Triplet类实现Quartet类的示例-
示例import org.javatuples.Triplet;
import org.javatuples.Quartet;
public class MyDemo {
public static void main(String[] args) {
Triplettriplet = new Triplet("Gray", "Blue", "Gray100");
System.out.println("Triplet elements = " + triplet);
Quartetquartet = triplet.add("Blue30");
System.out.println("Quartet (Implemented from Triplet) = " + quartet);
}
}
输出结果Triplet elements = [Gray, Blue, Gray100]
Quartet (Implemented from Triplet) = [Gray, Blue, Gray100, Blue30]
现在让我们来看另一个从Triplet实现Quartet类的示例。这将元素插入位置3rd-
示例import org.javatuples.Triplet;
import org.javatuples.Quartet;
public class MyDemo {
public static void main(String[] args) {
Triplettriplet = new Triplet("Gray", "Blue", "Gray100");
System.out.println("Triplet elements = " + triplet);
Quartetquartet = triplet.addAt2("Blue30");
System.out.println("Quartet (Implemented from Triplet) = " + quartet);
}
}
输出结果Triplet elements = [Gray, Blue, Gray100]
Quartet (Implemented from Triplet) = [Gray, Blue, Blue30, Gray100]