Write a method called removeInRange that accepts three param
Write a method called removeInRange that accepts three parameters, an ArrayList of Strings, a beginning
String, and an ending String, and removes from the list any Strings that fall alphabetically between the start
and end Strings. 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.
Solution
public static void removeInRange(ArrayList<String> a,String startString,String endString)
{
for(String a1 : a) {
if(a1.compareTo(startString)>0 && a1.compareTo(endString)<0)
a.remove(a1);
}
for(String a1:a)
{
System.out.print(a1 + \" \");
}
}
