Since the size of your string array is fixed at compile time, you'd be better off using a structure (like Pair
) that mandates exactly two fields, and thus avoid the runtime errors possible with the array approach.
Code:
Since Java doesn't supply a Pair
class, you'll need to define your own.
class Pair<A, B> {
public final A first;
public final B second;
public Pair(final A first, final B second) {
this.first = first;
this.second = second;
}
//
// Override 'equals', 'hashcode' and 'toString'
//
}
and then use it as:
List<Pair<String, String>> action = new ArrayList<Pair<String, String>>();
[ Here I used List
because it's considered a good practice to program to interfaces. ]