使用字符串java数组获取对象数据类型值

时间:2020-12-14 16:26:57

I want to iterate over an array list. I do also want to change the value each iteration of the list. For example:

我想迭代一个数组列表。我也想更改列表的每次迭代的值。例如:

    for (int i = 0; i < value.length; i++) {
        System.out.println(i+1, list.value[i]);
    }

My array for value looks like this:

我的值数组看起来像这样:

String [] value = {"identifier", "hyperlink", "children", "afterItemList", "beforeItemList"};

String [] value = {“identifier”,“hyperlink”,“children”,“afterItemList”,“beforeItemList”};

List declaration:

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;
}

I WANT TO:

我想要:

Print out like this:

打印出来像这样:

//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);
}

Is this possible to do?

这可能吗?

2 个解决方案

#1


-2  

for (int i = 0; i < value.length; i++) {
    System.out.println(list.value[i]);
    value[i] = "new";
}

try this

#2


-2  

for (String element : value) {
            System.out.println(element);
        }

change Your loop to this one.

将你的循环改为这一循环。

#1


-2  

for (int i = 0; i < value.length; i++) {
    System.out.println(list.value[i]);
    value[i] = "new";
}

try this

#2


-2  

for (String element : value) {
            System.out.println(element);
        }

change Your loop to this one.

将你的循环改为这一循环。