JavaTuples 元组迭代
JavaTuples 元组迭代的介绍
每个元组都实现了 Iterable 接口,并且可以以与集合类似的方式进行迭代。
Pair<String, Integer> pair = Pair.with("Test", Integer.valueOf(5));
for(Object object: Pair){
System.out.println(object);
}
JavaTuples 元组迭代的示例
在这里,我们将看到如何迭代元组。
package com.yiidian;
import org.javatuples.Quartet;
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"
);
for(Object object: triplet) {
System.out.print(object + " " );
}
System.out.println();
System.out.println(triplet);
String[] strArray = new String[] {"a", "b" , "c" , "d"};
Quartet<String, String, String, String> quartet = Quartet.fromArray(strArray);
for(Object object: quartet) {
System.out.print(object + " " );
}
System.out.println();
System.out.println("Quartet:" + quartet);
}
}
输出结果为:
热门文章
优秀文章