Implement Septet Class from Sextet Class in Java using JavaTuples

Java 8Object Oriented ProgrammingProgramming

Following is an example to implement Septet class from Sextet class in Java −

Example

import org.javatuples.Septet;
import org.javatuples.Sextet;
public class MyDemo {
   public static void main(String[] args) {
      Sextet<String, String, String, String, String, String>
         elements = new Sextet<String, String, String, String, String, String>(
         "One", "Two", "Three", "Four", "Five", "Six");
      System.out.println("Sextet elements = " + elements);
      Septet<String, String, String, String, String, String, String>septet = elements.add("Seven");
      System.out.println("Septet (implemented from Sextet class) = " + septet);
   }
}

Output

Sextet elements = [One, Two, Three, Four, Five, Six]
Septet (implemented from Sextet class) = [One, Two, Three, Four, Five, Six, Seven]

Let us now see another example. Here, we are inserting element at position 2nd −

Example

import org.javatuples.Septet;
import org.javatuples.Sextet;
public class MyDemo {
   public static void main(String[] args) {
      Sextet<String, String, String, String, String, String>
         elements = new Sextet<String, String, String, String, String, String>("One", "Two", "Three", "Four", "Five", "Six");
      System.out.println("Sextet elements = " + elements);
      Septet<String, String, String, String, String, String, String>septet = elements.addAt1("Seven");
      System.out.println("Septet (implemented from Sextet class) = " + septet);
   }
}

Output

Sextet elements = [One, Two, Three, Four, Five, Six]
Septet (implemented from Sextet class) = [One, Seven, Two, Three, Four, Five, Six]
raja
Updated on 24-Sep-2019 07:32:11

Advertisements