我有一种方法可以返回一个带有两个数组列表的对象:
return new Object[] {work, play};
我正试图用另一种方法让他们回来。我曾尝试强制转换为 ArrayList,但我收到错误“需要数组,但找到了 java.lang.Object”。
ArrayList setWork = (ArrayList)obj[0];
ArrayList setPlay = (ArrayList)obj[1];
ArrayList 创建的完整代码:
public static Object[] getWorkandPlay(ArrayList al) {
ArrayList work = new ArrayList();
ArrayList play = new ArrayList();
for (int i=0; i<al.size(); i++){
String item = (String) al.get(i);
if (item.startsWith("w.")) {
System.out.println("w " + item);
work.add(item);
} else if (item.startsWith("p.")) {
System.out.println("p " + item);
play.add(item);
} else {
System.out.println("Entries must start with either w. or p.\n");
}
}
return new Object[] {work, play};
}