Related Articles

Related Articles

Implement Quartet Class with Triplet Class in Java using JavaTuples
  • Last Updated : 20 Sep, 2018

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]

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.




My Personal Notes arrow_drop_up
Recommended Articles
Page :