Implement Decade Class from Ennead Class in Java using JavaTuples

Java 8Object Oriented ProgrammingProgramming

Following is an example to implement Decade Class from Ennead Class in Java using JavaTuples −

Example

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);
   }
}

Output

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]

Let us now see another example wherein we are using the addAt1() method. This adds an element at the position 2nd. This also implements Decade class from Ennead −

Example

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);
   }
}

Output

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]
raja
Published on 20-Sep-2019 07:33:40
Advertisements