使用JavaTuples在Java中从Octet类实现Ennead类
以下是从Java中的Octet类实现Ennead类的示例-
示例
import org.javatuples.Octet; import org.javatuples.Ennead; public class MyDemo { public static void main(String[] args) { Octet<String, String, String, String, String, String, String, String> octet = new Octet<String, String, String, String, String, String, String, String>( "Jack", "Tom", "Steve", "Tim", "Nathan", "Ryan", "Kevin", "Katie"); System.out.println("Octet elements = " + octet); Ennead<String, String, String, String, String, String, String, String, String>ennead = octet.add("Scarlett"); System.out.println("Ennead (implemented from Octet): " + ennead); } }
输出结果
Octet elements = [Jack, Tom, Steve, Tim, Nathan, Ryan, Kevin, Katie] Ennead (implemented from Octet): [Jack, Tom, Steve, Tim, Nathan, Ryan, Kevin, Katie, Scarlett]
现在让我们看到另一个示例,其中将使用addAt2()。该方法在位置3rd处插入。这也实现了Octet类的Ennead类-
示例
import org.javatuples.Octet; import org.javatuples.Ennead; public class MyDemo { public static void main(String[] args) { Octet<String, String, String, String, String, String, String, String> octet = new Octet<String, String, String, String, String, String, String, String>( "Jack", "Tom", "Steve", "Tim", "Nathan", "Ryan", "Kevin", "Katie"); System.out.println("Octet elements = " + octet); Ennead<String, String, String, String, String, String, String, String, String>ennead = octet.addAt2("Jacob"); System.out.println("Ennead (implemented from Octet): " + ennead); } }
输出结果
Octet elements = [Jack, Tom, Steve, Tim, Nathan, Ryan, Kevin, Katie] Ennead (implemented from Octet): [Jack, Tom, Jacob, Steve, Tim, Nathan, Ryan, Kevin, Katie]