📅  最后修改于: 2020-11-15 03:28:37             🧑  作者: Mango
org.javatuples.Quintet类表示具有五个元素的元组。
以下是org.javatuples.Quintet类的声明-
public final class Quintet
extends Tuple
implements IValue0, IValue1,
IValue2, IValue3, IValue4
Sr.No. | Constructor & Description |
---|---|
1 |
Quintet(A value0, B value1, C value2, D value3, E value4) This creates a Quintet Tuple. |
Sr.No. | Method & Description |
---|---|
1 |
Sextet add(Unit tuple) This method returns a Sextet tuple. Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Septet and upto add(Quintet tuple) returns Decade tuple. |
2 |
Sextet add(X0 value) This method add a value to the tuple and returns a Sextet tuple. Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Septet and so on upto add() with five parameters. |
3 |
Sextet addAt0(Unit value) This method add a Unit tuple at index 0 and returns a Sextet tuple. Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Septet and so on upto addAt0(Quintet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt4(Quintet). |
4 |
Sextet addAt0(X0 value) This method add a value at index 0 and returns a Sextet tuple. Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Septet and so on upto addAt0() with five parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt4() with five parameters. |
5 |
static Create tuple from array. |
6 |
static Create tuple from collection. |
7 |
static Create tuple from iterable. |
8 |
static Create tuple from iterable, starting from the specified index. |
9 |
int getSize() Return the size of the tuple. |
10 |
A getValue0() Returns the value of the tuple at index 0. Similarly getValue1() upto getValue4() returns the value at index 1 and so on. |
11 |
Quartet removeFrom0() Return the tuple after removing value of the tuple at index 0. Similarly removeFrom1() upto removeFrom4() returns the tuple after removing value of the tuple at index 1 and so on. |
12 |
Set the value of the tuple at index 0. |
13 |
static Quintet with(A value0, B value1, C value2, D value3, E value4) Create the tuple using given value. |
此类从以下类继承方法-
org.javatuples.Tuple
目的
让我们看看五重奏类的实际效果。在这里,我们将看到如何使用各种方法。
在C:\> JavaTuples中创建一个名为TupleTester的Java类文件。
文件:TupleTester.java
package com.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
import org.javatuples.Quartet;
import org.javatuples.Quintet;
import org.javatuples.Sextet;
import org.javatuples.Triplet;
public class TupleTester {
public static void main(String args[]){
Quintet quintet
= Quintet.with(5, 6, 7,8,9);
System.out.println(quintet);
boolean isPresent = quintet.contains(5);
System.out.println("5 is present: " + isPresent);
List list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
Sextet sextet
= quintet.add("Test");
System.out.println(sextet);
Integer value = quintet.getValue0();
System.out.println(value);
Quartet quartet = quintet.removeFrom0();
System.out.println(quartet);
Quintet quintet1
= Quintet.fromCollection(list);
System.out.println(quintet1);
}
}
验证结果
使用javac编译器编译类,如下所示:
C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
现在运行TupleTester以查看结果-
C:\JavaTuples>java -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
验证输出
[5, 6, 7, 8, 9]
5 is present: true
[5, 6, 7, 8, 9, Test]
5
[6, 7, 8, 9]
[1, 2, 3, 4, 5]