java List里面是一维数组,求输出此数组

2024-12-31 02:35:23
推荐回答(5个)
回答1:

public static void main(String[] args)
{
Object[] s = {123,"abc"};
List list = new ArrayList();
list.add(s);
for (int i = 0; i < list.size(); i++) {
Object[] obj=(Object[]) list.get(i);
for(Object o:obj){
System.out.println(o);
}
}

}
兄弟,上面这样做是否是有点多余;你是不是想下面这样:
public static void main(String[] args)
{
Object[] s = {123,"abc"};
List list = new ArrayList();
for(int i=0;i list.add(s[i]);
}
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}

}

回答2:

public static void main(String[] args) {

Object[] s = { 123, "abc" };

List list = new ArrayList();

list.add(s);

// System.out.println(list.size());

for (Object object : list) {

for (int i = 0; i < ((Object[]) object).length; i++) {

System.out.println(((Object[]) object)[i]);

}

}

}


回答3:

回答4:

list.get(i).toString()

回答5:

0bject[] s?···错误里面不是说了?