Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavaImplement Quartet Class with Triplet Class in Java using JavaTuples

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




    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", "Lazyroar");
      
            // 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, Lazyroar]
    [Quartet 1, Triplet 1, 1, Lazyroar]
  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", "Lazyroar");
      
            // 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, Lazyroar]
    Quartet: [Triplet 1, 1, Lazyroar, 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", "Lazyroar");
      
            // 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, Lazyroar]
    Quartet: [Quartet 1, Triplet 1, 1, Lazyroar]

    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", "Lazyroar");
      
            // 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, Lazyroar]
    Quartet: [Triplet 1, Quartet 1, 1, Lazyroar]

    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", "Lazyroar");
      
            // 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, Lazyroar]
    Quartet: [Triplet 1, 1, Quartet 1, Lazyroar]

    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", "Lazyroar");
      
            // 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, Lazyroar]
    Quartet: [Triplet 1, 1, Lazyroar, Quartet 1]
RELATED ARTICLES

Most Popular

Recent Comments