使用 JavaTuples 在 Java 中使用 Quartet 类实现 Quintet 类
以下是一个示例,展示如何在 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]
广告