Implement Quartet Class with Triplet Class in Java using JavaTuples

Following are the ways to implement Quartet Class with Triplet Class

  1. Using direct values
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    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()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:



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

    Program 2: Adding at Position 1 using addAt1()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    Program 3: Adding at Position 2 using addAt2()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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

    Program 4: Adding at Position 3 using addAt3()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.