public static ArrayList<String> remove(ArrayList<String> list, int a) {
for(int i = 0; i < list.size(); i++){
list.remove(i);
}
return list;
}
Why doesn't this code remove every element in my array? It seems to skip some. When I print the arraylist at the end it should be blank but it prints it with some elements still in there.
Edit (more code):
public static void main(String [] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter some a list of words:");
String line = scan.nextLine();
String[] words = line.split(" +");
ArrayList<String> list = new ArrayList<String>();
for(int i=0; i<words.length; i++){
list.add(words[i]);
}
System.out.println("Remove words less than how many characters?");
int a = scan.nextInt();
remove(list,a);
System.out.println(list);
}
aparameter for in this method? Please also post the code you're using to test this method and print the results.ato yourremove, what is it for?list.remove(i--);when I need this functionality.