【发布时间】:2018-07-13 12:47:28
【问题描述】:
我想遍历一个数组列表。我还想更改列表的每次迭代value。例如:
for (int i = 0; i < value.length; i++) {
System.out.println(i+1, list.value[i]);
}
value 的数组如下所示:
String [] value = {"identifier", "hyperlink", "children", "afterItemList", "beforeItemList"};
列表声明:
public class ItemAndAttributeObject {
String hyperlink;
String identifier;
String title;
String parentUniqueUrl;
String functionType;
ArrayList<String> children;
ArrayList<String> attributeList;
ArrayList<String> afterItemList;
ArrayList<String> beforeItemList;
public ItemAndAttributeObject(String title, String identifier, String hyperlink, String parentUniqueUrl, String functionType, ArrayList<String> children, ArrayList<String> attributeList, ArrayList<String> afterItemList, ArrayList<String> beforeItemList) {
this.hyperlink = hyperlink;
this.identifier = identifier;
this.title = title;
this.children = children;
this.functionType = functionType;
this.parentUniqueUrl = parentUniqueUrl;
this.attributeList = attributeList;
this.afterItemList = afterItemList;
this.beforeItemList = beforeItemList;
}
我想:
像这样打印出来:
//FIRST ITTERATION
for (int i = 0; i < value.length; i++) {
System.out.println(i+1, list.identifier);
}
//SECOND ITTERATION
for (int i = 0; i < value.length; i++) {
System.out.println(i+1, list.hyperlink);
}
//THIRD ITTERATION
for (int i = 0; i < value.length; i++) {
System.out.println(i+1, list.children);
}
//FOURTH ITTERATION
for (int i = 0; i < value.length; i++) {
System.out.println(i+1, list.afterItemList);
}
这样可以吗?
【问题讨论】:
-
您希望得到的预期结果是什么?
-
这个不太清楚。
-
list.value[0] = "new value"?请参阅How to Ask 和edit 你的问题更清楚你想要什么。 -
是否要打印
list的成员的值,称为identifier、hyperlink等? -
好吧,如果是这样,你能分享一下什么
list实际上是什么?我的意思是类声明