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