Las siguientes son las formas de implementar Quartet Class con Triplet Class
- Usando valores directos
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);
}
}
Producción:
[Triplet 1, 1, GeeksforGeeks] [Quartet 1, Triplet 1, 1, GeeksforGeeks]
- Usando el método Triplet.add()
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);
}
}
Producción:
Triplet: [Triplet 1, 1, GeeksforGeeks] Quartet: [Triplet 1, 1, GeeksforGeeks, Quartet 1]
- Usando el método Triplet.addAtX()
Programa 1: Agregar en la Posición 0 usando 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"
,
"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);
}
}
Producción:
Triplet: [Triplet 1, 1, GeeksforGeeks] Quartet: [Quartet 1, Triplet 1, 1, GeeksforGeeks]
Programa 2: Agregar en la Posición 1 usando 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"
,
"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);
}
}
Producción:
Triplet: [Triplet 1, 1, GeeksforGeeks] Quartet: [Triplet 1, Quartet 1, 1, GeeksforGeeks]
Programa 3: Agregar en la Posición 2 usando 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"
,
"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);
}
}
Producción:
Triplet: [Triplet 1, 1, GeeksforGeeks] Quartet: [Triplet 1, 1, Quartet 1, GeeksforGeeks]
Programa 4: Agregar en la Posición 3 usando 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"
,
"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);
}
}
Producción:
Triplet: [Triplet 1, 1, GeeksforGeeks] Quartet: [Triplet 1, 1, GeeksforGeeks, Quartet 1]