It's a simple double-loop:
for(int x = 0; x < 275; x++) {
final String first = arrayOfStrings[x];
for(int y = 0; y < 275; y++) {
if(y == x) continue; // will properly increase y
final String second = arrayOfStrings[y];
// TODO: do stuff with first and second.
}
}
Edit: as the comments noted, if the elements [a, b, c]
have only one ab
and thus not ba
, (called combination), then the following code will work:
final ArrayList<String> collected = new ArrayList<String>();
for(int x = 0; x < 275; x++) {
for(int y = 0; y < 275; y++) {
if(y == x) continue; // will properly increase y
final String p1 = arrayOfStrings[x] + arrayOfStrings[y];
final String p2 = arrayOfStrings[y] + arrayOfStrings[x];
if(!collected.contains(p1) && !collected.contains(p2)) {
collected.add(p1);
}
}
}
// TODO: do stuff with collected