This post shows, How to remove all vowels from a string in java? with the help of replaceAll() method.
Remove vowels from a string in java:
Explanation:
Removing vowels in java is easy, we will take the user input with the help of a Scanner class. we will use replaceAll() which takes in two parameters, one is the string to be replaced and another one is the string to be replaced with.
Also, the vowels are “aeiou” so we replace those vowel letters by an empty string (“”) for both uppercase and lowercase vowel letters. Then print the result string without vowels.
Java Program to Remove all the Vowels from a String.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import java.util.Scanner; public class RemoveVowel { public static void main(String[] args) { Scanner sc = new Scanner(System.in); //user input System.out.println("Enter the string:"); String inputStr = sc.nextLine(); String resultStr = inputStr.replaceAll("[AEIOUaeiou]", ""); System.out.println("Result String without vowels:"); System.out.println(resultStr); sc.close(); } } |
The output of removing vowels from a string in java: