使用JavaTuples从Java中的Ennead类实现Decade类
以下是使用JavaTuples从Java中的Ennead类实现Decade类的示例-
示例
import org.javatuples.Decade; import org.javatuples.Ennead; public class MyDemo { public static void main(String[] args) { Ennead<String, String, String, String, String, String, String, String, String> e = Ennead.with("Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob"); System.out.println("Ennead elements= " + e); Decade<String, String, String, String, String, String, String, String, String, String> decade = e.add("Amy"); System.out.println("Decade elements (implemented from Ennead) = " + decade); } }
输出结果
Ennead elements= [Katie, Tom, Ryan, Tom, Bradley, David, Steve, Brad, Jacob] Decade elements (implemented from Ennead) = [Katie, Tom, Ryan, Tom, Bradley, David, Steve, Brad, Jacob, Amy]
现在让我们看看另一个示例,其中我们正在使用addAt1()方法。这会在位置2nd处添加一个元素。这也实现了Ennead的Decade类-
示例
import org.javatuples.Decade; import org.javatuples.Ennead; public class MyDemo { public static void main(String[] args) { Ennead<String, String, String, String, String, String, String, String, String> e = Ennead.with("Katie", "Tom","Ryan", "Tom","Bradley", "David","Steve", "Brad", "Jacob"); System.out.println("Ennead elements= " + e); Decade<String, String, String, String, String, String, String, String, String, String>decade = e.addAt1("Amy"); System.out.println("Decade elements (implemented from Ennead) = " + decade); } }
输出结果
Ennead elements= [Katie, Tom, Ryan, Tom, Bradley, David, Steve, Brad, Jacob] Decade elements (implemented from Ennead) = [Katie, Amy, Tom, Ryan, Tom, Bradley, David, Steve, Brad, Jacob]