Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method called removeInRange that accepts three parameters, an ArrayList

ID: 3921352 • Letter: W

Question

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.

Explanation / Answer

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 + " ");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote