I will go over how to implement each of the approaches you mentioned.
There is a Pair
class in the Apache Common Lang API, which technically isn't part of the "standard" library. You can download it at http://commons.apache.org/proper/commons-lang/.
The documentation of Pair
is here.
You can use it like this:
// in the method
public Pair<ArrayList, ArrayList> yourMethod() {
...
return ImmutablePair.of(yourArrayList1, yourArrayList2);
}
// when you call the method
Pair<ArrayList, ArrayList> pair = yourMethod();
pair.getLeft(); // gets you the first array list
pair.getRight(); // gets you the second array list
You can also create your own Pair
class, which is essentially what your second approach is trying to do.
Here's an example from this post.
public class Pair<K, V> {
private final K element0;
private final V element1;
public static <K, V> Pair<K, V> createPair(K element0, V element1) {
return new Pair<K, V>(element0, element1);
}
public Pair(K element0, V element1) {
this.element0 = element0;
this.element1 = element1;
}
public K getElement0() {
return element0;
}
public V getElement1() {
return element1;
}
}
You can use it like this:
// in the method
public Pair<ArrayList, ArrayList> yourMethod() {
...
return Pair.createPair(yourArrayList1, yourArrayList2);
}
// when you call the method
Pair<ArrayList, ArrayList> pair = yourMethod();
pair.getElement0(); // gets you the first array list
pair.getElement1(); // gets you the second array list