I have one method that returns an object with two arraylists:
return new Object[] {work, play};
I am trying to get them back out in another method. I have tried casting to ArrayList but I get the error ‘array required, but java.lang.Object found’.
ArrayList setWork = (ArrayList)obj[0];
ArrayList setPlay = (ArrayList)obj[1];
Full code for ArrayList creation:
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};
}
I am doing something like this based on your code and it works…
output