We are given a list of words in the form of an ArrayList as follows:
public ArrayList<String> getListOfStrings(){
ArrayList<String> list = new ArrayList<String>();
list.add("This");
list.add("is");
list.add("an");
list.add("exercise");
list.add("to");
list.add("illustrate");
list.add("the");
list.add("use");
list.add("of");
list.add("ArrayLists");
list.add(".");
return list;
}
How do I write a method that removes all words in that list (i.e. all the objects in the ArrayList) that have the length "len" entered by the user?
I already wrote a method that lists all the words of length "len" entered by the user, and it works, it's as follows:
public ArrayList<String>getWordsWithLength(int len, ArrayList<String> lijst){
ArrayList<String> list = new ArrayList<String>();
for(String woord: lijst){
if(woord.length()==len){
list.add(woord);
}
}
return(list);
}
But as a beginner in java, I'm stuck on how to remove the words of length "len". Please help! (I am under the impression that you start by removing them from the end of the list, back-to-front as it were)