JavaTuples - Sextet 类
org.javatuples.Sextet 类表示具有六个元素的元组。
类声明
以下是 org.javatuples.Sextet 类的声明
public final class Sextet
extends Tuple
implements IValue0 , IValue1,
IValue2, IValue3, IValue4,
IValue5
类构造器
Sr.No. | Constructor & Description |
---|---|
1 | Sextet(A value0, B value1, C value2, D value3, E value4, F value5) This creates a Sextet Tuple. |
类方法
Similarly setAt1() upto setAt5() set the value at index 1, and so on.
Sr.No. | Method & Description |
---|---|
1 | Septet add(Unit tuple) This method returns a Septet tuple. Similarly other methods to add tuples are available e.g. add(Pair tuple) returns Octet and upto add(Quartet tuple) returns Decade tuple. |
2 | Septet add(X0 value) This method add a value to the tuple and returns a Septet tuple. Similarly other methods to add values are available e.g. add(X0 value0, X1 value1) returns Octet and so on upto add() with four parameters. |
3 | Septet addAt0(Unit value) This method add a Unit tuple at index 0 and returns a Septet tuple. Similarly other methods to add tuples are available e.g. addAt0(Pair value) returns Octet and so on upto addAt0(Quartet). Other similar method are addAt1(Unit value) which add a unit at index0 and have similar methods upto addAt5(Quartet). |
4 | Septet addAt0(X0 value) This method add a value at index 0 and returns a Septet tuple. Similarly other methods to add values are available e.g. addAt0(X0 value0, X1 value1) returns Octet and so on upto addAt0() with four parameters. Other similar method are addAt1(X0 value) which add a value at index0 and have similar methods upto addAt5() with four parameters. |
5 | static Sextet<x,x,x,x,x,x> fromArray(X[] array)</x,x,x,x,x,x> Create tuple from array. |
6 | static Sextet<x,x,x,x,x,x> fromCollection(Collection collection)</x,x,x,x,x,x> Create tuple from collection. |
7 | static Sextet<x,x,x,x,x,x> fromIterable(Iterable iterable)</x,x,x,x,x,x> Create tuple from iterable. |
8 | static Sextet<x,x,x,x,x,x> fromIterable(Iterable iterable, int index)</x,x,x,x,x,x> 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 getValue5() returns the value at index 1 and so on. |
11 | Quintet<b,c,d,e,f> removeFrom0()</b,c,d,e,f> Return the tuple after removing value of the tuple at index 0. Similarly removeFrom1() upto removeFrom5() returns the tuple after removing value of the tuple at index 1 and so on. |
12 | Sextet<x,b,c,d,e,f> setAt0(X value)</x,b,c,d,e,f> Set the value of the tuple at index 0. |
13 | static Sextet<a,b,c,d,e,f> with(A value0, B value1, C value2, D value3, E value4, F value5)</a,b,c,d,e,f> Create the tuple using given value. |
方法继承
此类从以下类继承方法
- org.javatuples.Tuple
- 目的
例
让我们看看 Sextet 类的实际应用。在这里,我们将看到如何使用各种方法。在 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.Septet;
public class TupleTester {
public static void main(String args[]){
Sextet sextet
= Sextet.with(5, 6, 7,8,9,10);
System.out.println(sextet);
boolean isPresent = sextet.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);
Septet septet
= sextet.add("Test");
System.out.println(septet);
Integer value = sextet.getValue0();
System.out.println(value);
Quintet quintet
= sextet.removeFrom0();
System.out.println(quintet);
Sextet sextet1
= Sextet.fromCollection(list);
System.out.println(sextet1);
}
}
验证结果
使用 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]
5 is present: true
[5, 6, 7, 8, 9, 10, Test]
5
[6, 7, 8, 9, 10]
[1, 2, 3, 4, 5, 6]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: 匀速圆周运动
下一篇: 彻底找到 Tomcat 启动速度慢的元凶
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论