以下是从Java中的Quartet类实现Quintet类的示例-
示例import org.javatuples.Quartet;
import org.javatuples.Quintet;
public class MyDemo {
public static void main(String[] args) {
Quartetquartet = new Quartet(
"Table", "Chair", "Pen", "Paper");
System.out.println("Quartet elements = " + quartet);
Quintetquintet = quartet.add("Notebook");
System.out.println("Quintet (implemented from Quartet) elements = " + quintet);
}
}
输出结果Quartet elements = [Table, Chair, Pen, Paper]
Quintet (implemented from Quartet) elements = [Table, Chair, Pen, Paper, Notebook]
现在让我们看一下另一个示例,该示例从Java中的Quartet类实现Quintet类-
示例import org.javatuples.Quartet;
import org.javatuples.Quintet;
public class MyDemo {
public static void main(String[] args) {
Quartetquartet = new Quartet(
"Notebook", "Chair", "Pen", "Table");
System.out.println("Quartet elements = " + quartet);
Quintetquintet = quartet.addAt0("Board");
System.out.println("Quintet (implemented from Quartet) elements = " + quintet);
}
}
输出结果Quartet elements = [Notebook, Chair, Pen, Table]
Quintet (implemented from Quartet) elements = [Board, Notebook, Chair, Pen, Table]