遍历Java Pair Tuple
通过JavaTuples中的Pair进行的迭代与您在JavaArrays集合中看到的相同。
首先让我们看看使用JavaTuples所需的工具。要在JavaTuples中使用Pair类,您需要导入以下包-
import org.javatuples.Pair;
注-下载和运行JavaTuples程序的步骤如果使用EclipseIDE在JavaTuples中运行PairClass,则右键单击Project→Properties→JavaBuildPath→AddExternalJars并上传下载的JavaTuplesjar文件。
以下是一个例子-
示例
import org.javatuples.Pair; public class Demo { public static void main(String[] args) { Pair < String, String > p = Pair.with("Mobile", "Desktop"); for (Object ob: p) System.out.println(ob); } }
输出结果
Mobile Desktop