If I understand your problem, you're doing the above in a function and want to get the function to return all three lists, list1, list2, and list3.
In this case, you could return an array of three lists, or an ArrayList
of three lists. In general, if I want a function that returns multiple values (that may not all be the same type), I usually just create a small class to contain them:
private static class KeywordSearchResults {
List<String[]> list1;
List<String[]> list2;
List<String[]> list3;
KeywordResults (List<String[]> list1, List<String[]> list2,
List<String[]> list3) {
this.list1 = list1; this.list2 = list2; this.list3 = list3;
}
}
(I usually do this as a nested class; whether to make it private
or public
depends on your needs.)
Normally it's a bad idea to declare a class with non-private fields, but I think if you're just using it as a wrapper just to return multiple values from a function or to create an object whose only purpose is to pass certain fields around together, and there aren't any other methods in the class, I think it's fine because the class doesn't really represent some "higher concept". Still, this is the kind of solution you'd adopt only when it's really appropriate; I think it's best to look around to see if there's a better design.