Implement Octet Class from Septet Class in Java using JavaTuples

Java 8Object Oriented ProgrammingProgramming

At first create Septet and add elements −

Septet<String, String, String, String, String, String, String>
   septet = new Septet<String, String, String, String, String, String, String>(
   "Laptop", "Desktop", "Tablet", "Notebook", "Phone", "Reader", "LCD");

Now, implement Octet from Septet −

Octet<String, String, String, String, String, String, String, String>
octet = septet.add("LED");

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

Example

import org.javatuples.Septet;
import org.javatuples.Octet;
public class MyDemo {
   public static void main(String[] args) {
      Septet<String, String, String, String, String, String, String>
         septet = new Septet<String, String, String, String, String, String, String>(
         "Laptop", "Desktop", "Tablet", "Notebook", "Phone", "Reader", "LCD");
      System.out.println("Septet elements = " + septet);
      Octet<String, String, String, String, String, String, String, String>octet = septet.add("LED");
      System.out.println("Octet (implemented from Septet) = " + octet);
   }
}

Output

Septet elements = [Laptop, Desktop, Tablet, Notebook, Phone, Reader, LCD]
Octet (implemented from Septet) = [Laptop, Desktop, Tablet, Notebook, Phone, Reader, LCD, LED]
raja
Updated on 20-Sep-2019 07:40:07

Advertisements