Java Data Type How to - Print a Scanner string without vowels








Question

We would like to know how to print a Scanner string without vowels.

Answer

//from  ww w.  ja  va2 s . c o  m
public class Main {

  public static void main(String argv[]) {

    String noVowels = takeOutVowel("Hello how are you?");
    System.out.println(noVowels); // prints "Hll hw r y?"
  }

  private static String takeOutVowel(String s) {
    return s.replaceAll("[aeiou]", "");
  }
}