Implement Quintet Class with Quartet Class in Java using JavaTuples

Java 8Object Oriented ProgrammingProgramming

Following is an example to implement Quintet class from Quartet class in Java −

Example

import org.javatuples.Quartet;
import org.javatuples.Quintet;
public class MyDemo {
   public static void main(String[] args) {
      Quartet<String, String, String, String>quartet = new Quartet<String, String, String, String>(
         "Table", "Chair", "Pen", "Paper");
      System.out.println("Quartet elements = " + quartet);
      Quintet<String, String, String, String, String>quintet = quartet.add("Notebook");
      System.out.println("Quintet (implemented from Quartet) elements = " + quintet);
   }
}

Output

Quartet elements = [Table, Chair, Pen, Paper]
Quintet (implemented from Quartet) elements = [Table, Chair, Pen, Paper, Notebook]

Let us now see another example to implement Quintet class from Quartet class in Java −

Example

import org.javatuples.Quartet;
import org.javatuples.Quintet;
public class MyDemo {
   public static void main(String[] args) {
      Quartet<String, String, String, String>quartet = new Quartet<String, String, String, String>(
         "Notebook", "Chair", "Pen", "Table");
      System.out.println("Quartet elements = " + quartet);
      Quintet<String, String, String, String, String>quintet = quartet.addAt0("Board");
      System.out.println("Quintet (implemented from Quartet) elements = " + quintet);
   }
}

Output

Quartet elements = [Notebook, Chair, Pen, Table]
Quintet (implemented from Quartet) elements = [Board, Notebook, Chair, Pen, Table]
raja
Published on 24-Sep-2019 07:27:56
Advertisements