使用 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() 方法。后者在第 2 位添加一个元素。这也从 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]

更新于: 20-Sep-2019

79 个浏览

开启你的 职业生涯

完成课程认证

立即开始
广告