Javatuples 简明教程
JavaTuples - Remove Elements
元组有removeAtX()方法来移除特定索引处的值。例如,Triplet 类有以下方法。
A tuple has removeAtX() methods to remove value at particular index. For example Triplet class has following methods.
-
removeAt0() − remove value at index 0 and return the resulted tuple.
-
removeAt1() − remove value at index 1 and return the resulted tuple.
-
removeAt2() − remove value at index 2 and return the resulted tuple.
移除一个元素会返回一个新的元组。
Removing an element returns a new tuple.
Example
让我们来看看 JavaTuples 的实际应用。这里我们将看到如何在元组中移除值。
Let’s see JavaTuples in action. Here we’ll see how to remove value in a tuple.
在 C:>JavaTuples 中创建一个名为 TupleTester 的 Java 类文件。
Create a java class file named TupleTester in C:\>JavaTuples.
文件:TupleTester.java
File: TupleTester.java
package com.tutorialspoint;
import org.javatuples.Pair;
import org.javatuples.Triplet;
public class TupleTester {
public static void main(String args[]){
Triplet<String, Integer, String> triplet = Triplet.with(
"Test1", Integer.valueOf(5), "Test2"
);
Pair<String, Integer> pair = triplet.removeFrom2();
System.out.println("Triplet:" + triplet);
System.out.println("Pair: " + pair);
}
}
Verify the result
Verify the result
使用以下 javac 编译器编译类:
Compile the classes using javac compiler as follows −
C:\JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
现在运行 TupleTester 查看结果:
Now run the TupleTester to see the result −
C:\JavaTuples>java -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester