Implement Quintet Class with Quartet Class in Java using JavaTuples

Following are the ways to implement Quintet Class with Quartet 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 Quartet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet", "Triplet", "Pair", "Unit");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
      
            // Create Quintet from Quartet
            Quintet<String, String, String, String, String>
                quintet = new Quintet<String, String, String, String, String>(
                    "Quintet 1",
                    quartet.getValue0(),
                    quartet.getValue1(),
                    quartet.getValue2(),
                    quartet.getValue3());
      
            // Print Quintet
            System.out.println("Quintet: " + quintet);
        }
    }

    chevron_right

    
    

    Output:

    [Quintet, Triplet 1, 1, GeeksforGeeks]
    [Quintet 1, Quintet, Triplet 1, 1, GeeksforGeeks]
  2. Using Quartet.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 Quartet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet", "Triplet", "Pair", "Unit");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
      
            // Create Quintet from Quartet
            Quintet<String, String, String, String, String>
                quintet = quartet.add("Quintet");
      
            // Print Quintet
            System.out.println("Quintet: " + quintet);
        }
    }

    chevron_right

    
    

    Output:

    Quartet: [Quartet, Triplet, Pair, Unit]
    Quintet: [Quartet, Triplet, Pair, Unit, Quintet]
  3. Using Quartet.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 Quartet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet", "Triplet", "Pair", "Unit");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
      
            // Create Quintet from Quartet
            Quintet<String, String, String, String, String>
                quintet = quartet.addAt0("Quintet");
      
            // Print Quintet
            System.out.println("Quintet: " + quintet);
        }
    }

    chevron_right

    
    

    Output:



    Quartet: [Quartet, Triplet, Pair, Unit]
    Quintet: [Quintet, Quartet, Triplet, Pair, Unit]

    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 Quartet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet", "Triplet", "Pair", "Unit");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
      
            // Create Quintet from Quartet
            Quintet<String, String, String, String, String>
                quintet = quartet.addAt1("Quintet");
      
            // Print Quintet
            System.out.println("Quintet: " + quintet);
        }
    }

    chevron_right

    
    

    Output:

    Quartet: [Quartet, Triplet, Pair, Unit]
    Quintet: [Quartet, Quintet, Triplet, Pair, Unit]

    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 Quartet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet", "Triplet", "Pair", "Unit");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
      
            // Create Quintet from Quartet
            Quintet<String, String, String, String, String>
                quintet = quartet.addAt2("Quintet");
      
            // Print Quintet
            System.out.println("Quintet: " + quintet);
        }
    }

    chevron_right

    
    

    Output:

    Quartet: [Quartet, Triplet, Pair, Unit]
    Quintet: [Quartet, Triplet, Quintet, Pair, Unit]

    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 addAt3() method with
    // direct value
      
    import java.util.*;
    import org.javatuples.*
      
        class GfG {
        public static void main(String[] args)
        {
            // create Quartet
            Quartet<String, String, String, String>
                quartet = new Quartet<String, String, String, String>(
                    "Quartet", "Triplet", "Pair", "Unit");
      
            // Print Quartet
            System.out.println("Quartet: " + quartet);
      
            // Create Quintet from Quartet
            Quintet<String, String, String, String, String>
                quintet = quartet.addAt3("Quintet");
      
            // Print Quintet
            System.out.println("Quintet: " + quintet);
        }
    }

    chevron_right

    
    

    Output:

    Quartet: [Quartet, Triplet, Pair, Unit]
    Quintet: [Quartet, Triplet, Pair, Quintet, Unit]

    Program 5: Adding at Position 4 using addAt4()

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    Quartet: [Quartet, Triplet, Pair, Unit]
    Quintet: [Quartet, Triplet, Pair, Unit, Quintet]


    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.