Implement Ennead Class from Octet Class in Java using JavaTuples

Java 8Object Oriented ProgrammingProgramming

Following is an example to implement Ennead class from Octet class in Java −

Example

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

Output

Octet elements = [Jack, Tom, Steve, Tim, Nathan, Ryan, Kevin, Katie]
Ennead (implemented from Octet): [Jack, Tom, Steve, Tim, Nathan, Ryan, Kevin, Katie, Scarlett]

Let us now see another example wherein we will be using addAt2(). This method inserts at position 3rd. This also implements Ennead class from Octet class −

Example

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

Output

Octet elements = [Jack, Tom, Steve, Tim, Nathan, Ryan, Kevin, Katie]
Ennead (implemented from Octet): [Jack, Tom, Jacob, Steve, Tim, Nathan, Ryan, Kevin, Katie]
raja
Updated on 20-Sep-2019 07:37:27

Advertisements