Skip to content
Related Articles

Related Articles

Implement Quartet Class with Triplet Class in Java using JavaTuples
  • Last Updated : 20 Sep, 2018
GeeksforGeeks - Summer Carnival Banner

Following are the ways to implement Quartet Class with Triplet Class

  1. Using direct values




    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
        public static void main(String[] args)
        {
      
            // create Triplet
            Triplet<String, String, String>
                triplet = new Triplet<String, String, String>(
                    "Triplet 1", "1", "GeeksforGeeks");
      
            // Print Triplet
            System.out.println("Triplet: " + triplet);
      
            // Create Quartet from Triplet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet 1",
                    triplet.getValue0(),
                    triplet.getValue1(),
                    triplet.getValue2());
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
        }
    }

    Output:

    [Triplet 1, 1, GeeksforGeeks]
    [Quartet 1, Triplet 1, 1, GeeksforGeeks]
  2. Using Triplet.add() method




    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
        public static void main(String[] args)
        {
            // create Triplet
            Triplet<String, String, String>
                triplet = new Triplet<String, String, String>(
                    "Triplet 1", "1", "GeeksforGeeks");
      
            // Print Triplet
            System.out.println("Triplet: " + triplet);
      
            // Using add() to create Quartet
            Quartet<String, String, String, String>
                quartet = triplet.add("Quartet 1");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
        }
    }

    Output:

    Triplet: [Triplet 1, 1, GeeksforGeeks]
    Quartet: [Triplet 1, 1, GeeksforGeeks, Quartet 1]
  3. Using Triplet.addAtX() method

    Program 1: Adding at Position 0 using addAt0()




    // Below is a Java program to demonstrate
    // use of addAt0() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            /// create Triplet
            Triplet<String, String, String>
                triplet = new Triplet<String, String, String>(
                    "Triplet 1", "1", "GeeksforGeeks");
      
            // Print Triplet
            System.out.println("Triplet: " + triplet);
      
            // Using add() to create Quartet
            Quartet<String, String, String, String>
                quartet = triplet.addAt0("Quartet 1");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
        }
    }

    Output:



    Triplet: [Triplet 1, 1, GeeksforGeeks]
    Quartet: [Quartet 1, Triplet 1, 1, GeeksforGeeks]

    Program 2: Adding at Position 1 using addAt1()




    // Below is a Java program to demonstrate
    // use of addAt1() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*;
      
    class GfG {
        public static void main(String[] args)
        {
            // create Triplet
            Triplet<String, String, String>
                triplet = new Triplet<String, String, String>(
                    "Triplet 1", "1", "GeeksforGeeks");
      
            // Print Triplet
            System.out.println("Triplet: " + triplet);
      
            // Using add() to create Quartet
            Quartet<String, String, String, String>
                quartet = triplet.addAt1("Quartet 1");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
        }
    }

    Output:

    Triplet: [Triplet 1, 1, GeeksforGeeks]
    Quartet: [Triplet 1, Quartet 1, 1, GeeksforGeeks]

    Program 3: Adding at Position 2 using addAt2()




    // Below is a Java program to demonstrate
    // use of addAt2() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            // create Triplet
            Triplet<String, String, String>
                triplet = new Triplet<String, String, String>(
                    "Triplet 1", "1", "GeeksforGeeks");
      
            // Print Triplet
            System.out.println("Triplet: " + triplet);
      
            // Using add() to create Quartet
            Quartet<String, String, String, String>
                quartet = triplet.addAt2("Quartet 1");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
        }
    }

    Output:

    Triplet: [Triplet 1, 1, GeeksforGeeks]
    Quartet: [Triplet 1, 1, Quartet 1, GeeksforGeeks]

    Program 4: Adding at Position 3 using addAt3()




    // Below is a Java program to demonstrate
    // use of addAt2() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            // create Triplet
            Triplet<String, String, String>
                triplet = new Triplet<String, String, String>(
                    "Triplet 1", "1", "GeeksforGeeks");
      
            // Print Triplet
            System.out.println("Triplet: " + triplet);
      
            // Using add() to create Quartet
            Quartet<String, String, String, String>
                quartet = triplet.addAt3("Quartet 1");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
        }
    }

    Output:

    Triplet: [Triplet 1, 1, GeeksforGeeks]
    Quartet: [Triplet 1, 1, GeeksforGeeks, Quartet 1]

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :