I have been trying to merge two string arraylists that are already alphabetically sorted, into 1 big one that also turns out to be alphabetically sorted. It is preferred that this is done using one loop but two are fine too. Also the comapreTo method must be used to compare the Strings. This is what I have but it doesn't work. It might be better for you to just start over as this is probably not very well wrtitten.
public static ArrayList<String> merge(ArrayList<String> al1, ArrayList<String> al2){
ArrayList<String> result = new ArrayList<String>();
int longLength = al1.size() > al2.size() ? al1.size():al2.size();
for(int i=0;i<longLength;i++){
if(al1.size() > i && al2.size() > i && al1.get(i).compareTo(al2.get(i)) >= 0){
result.add(al2.get(i));
}
else if(al1.size() > i && al2.size() > i && al1.get(i).compareTo(al2.get(i)) < 0) {
result.add(al1.get(i));
}
else if(al1.size() > i && al2.size() <= i) {
result.add(al1.get(i));
}
else if(al1.size() <= i && al2.size() > i) {
result.add(al2.get(i));
}
}
return result;
}