📅  最后修改于: 2020-11-15 03:30:40             🧑  作者: Mango
org.javatuples.Decade类表示具有十个元素的元组。
以下是org.javatuples.Decade类的声明-
public final class Decade
extends Tuple
implements IValue0, IValue1,
IValue2, IValue3, IValue4,
IValue5, IValue6, IValue7,
IValue8, IValue9
Sr.No. | Constructor & Description |
---|---|
1 |
Decade(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8, I value9 ) This creates a Decade Tuple. |
Sr.No. | Method & Description |
---|---|
1 |
static Create tuple from array. |
2 |
static Create tuple from collection. |
3 |
static Create tuple from iterable. |
4 |
static Create tuple from iterable, starting from the specified index. |
5 |
int getSize() Return the size of the tuple. |
6 |
A getValue0() Returns the value of the tuple at index 0. Similarly getValue1() upto getValue9() returns the value at index 1 and so on. |
7 |
Ennead removeFrom0() Return the tuple after removing value of the tuple at index 0. Similarly removeFrom1() upto removeFrom9() returns the tuple after removing value of the tuple at index 1 and so on. |
8 |
Set the value of the tuple at index 0. |
9 |
static Decade with(A value0, B value1, C value2, D value3, E value4, F value5, G value6, H value7, I value8, I value9) Create the tuple using given value. |
此类从以下类继承方法-
org.javatuples.Tuple
目的
让我们看看Ennead类的实际应用。在这里,我们将看到如何使用各种方法。
在C:\> JavaTuples中创建一个名为TupleTester的Java类文件。
文件:TupleTester.java
package com.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
import org.javatuples.Decade;
import org.javatuples.Ennead;
public class TupleTester {
public static void main(String args[]){
Decade
decade = Decade.with(5, 6, 7,8,9,10,11,12,13,14);
System.out.println(decade);
boolean isPresent = decade.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);
list.add(6);
list.add(7);
list.add(8);
list.add(9);
list.add(10);
Integer value = decade.getValue0();
System.out.println(value);
Ennead ennead = decade.removeFrom0();
System.out.println(ennead);
Decade
decade1 = Decade.fromCollection(list);
System.out.println(decade1);
}
}
验证结果
使用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, 10, 11, 12, 13, 14]
5 is present: true
5
[6, 7, 8, 9, 10, 11, 12, 13, 14]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]