我的配对班:
public class Pair<o,t> {
private o one;
private t two;
public Pair(o one, t two) {
this.one = one;
this.two = two;
}
public o getO() {
return one;
}
public void setO(o one) {
this.one = one;
}
public t getT() {
return two;
}
public void setT(t two) {
this.two= two;
}
}
在我的主应用程序中,我用 pair 对象填充了一个列表:
List<Pair<Integer, String>> test = new ArrayList<Pair<Integer, String>>();
Pair<Integer, String> pair;
pair.setO(1);
pair.setT("A");
test.add(pair);
pair.setO(2);
pair.setT("B");
test.add(pair);
我希望能够仅通过列表索引获取整数值,例如。for循环写出A,B等。我该怎么做?有没有更简单的方法在 Java 中做这样的事情?