Write a method called removeInRange that accepts three parameters, an ArrayList of String s, a beginning String , and an ending String , and removes from the list any String s that fall alphabetically between the start and end String s. For example, if the method is passed a list containing the elements (“to”, “be”, “or”, “not”, “to”, “be”, “that”, “is”, “the”, “question”), “free” as the start String , and “rich” as the end String , the list’s elements should be changed to (“to”, “be”, “to”, “be”, “that”, “the”). The “or”, “not”, “is”, and “question” should be removed because they occur alphabetically between “free” and “rich”. You may assume that the start String alphabetically precedes the ending String.
public static void removeInRange(ArrayList strList,
String start, String end)
{
for(int i = 0; i < strList.size(); i++)
{
if(strList.get(i).compareTo(start) > 0
&& strList.get(i).compareTo(end) < 0)
{
strList.remove(i);
i--;
}
}
}