在Java中用JavaTuples实现quitte类和quarte类
以下是从Java中的Quartet类实现Quintet类的示例-
示例
import org.javatuples.Quartet; import org.javatuples.Quintet; public class MyDemo { public static void main(String[] args) { Quartet<String, String, String, String>quartet = new Quartet<String, String, String, String>( "Table", "Chair", "Pen", "Paper"); System.out.println("Quartet elements = " + quartet); Quintet<String, String, String, String, String>quintet = 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) { Quartet<String, String, String, String>quartet = new Quartet<String, String, String, String>( "Notebook", "Chair", "Pen", "Table"); System.out.println("Quartet elements = " + quartet); Quintet<String, String, String, String, String>quintet = 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]