Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Implement Quintet Class with Quartet Class in Java using JavaTuples

  • Last Updated : 20 Sep, 2018

Following are the ways to implement Quintet Class with Quartet Class

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.

  1. Using direct values




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

    Output:

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




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

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






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

    Output:

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

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

    Output:

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

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

    Output:

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

    Program 4: Adding at Position 3 using addAt3()




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

    Output:

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

    Program 5: Adding at Position 4 using addAt4()




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

    Output:

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



    My Personal Notes arrow_drop_up
Recommended Articles
Page :