0

How do you remove all certain elements or characters from an ArrayList?

Let's say I have a scanner object like

Scanner keyboard = new Scanner(System.in);
String userInput = keyboard.nextLine();

And the user inputs something like

Bubblesort.=

If I wanted to save the characters of the String variable to an ArrayList, I'd use a char ArrayList and then load the characters in using a for loop like so

ArrayList<Character> stringArrayList = new ArrayList<Character>();
for (int i = 0; i < userInput.length(); i++) {
    stringArrayList.add(userInput.charAt(i));
}

My question is, how do I remove all the characters which aren't letters. Like '.', and '=' so that the ArrayList contains only the word "Bubblesort"?

Joshua
  • 19
  • 1
  • 3

0 Answers0