Remove vowels from string java – Java Program to Delete all Vowel Characters from String

Remove vowels from string java: Provided list of Simple Java Programs is specially designed for freshers and beginners to get familiarize with the concepts of Java programming language and become pro in coding.

Java Program to Delete all Vowel Characters from String

  • Java program to remove all vowel alphabets from a string using replaceAll() method.
  • Java program to delete all vowels from a string without using any library function.

In this java program, we have to delete all occurrences of vowel characters from a given string and then print it on screen.

For Example,
Input String : BTechGeeks
Output String : BTechGeeks
Here, we are going to use two approaches of removing vowel alphabets from strings.

Java program to delete vowels from string using replaceAll method.

Remove vowels from string: Here we are going to use replaceAll() method of String class. This method replaces any occurrence of any vowel character(lowercase or uppercase) with “”. We are using “[AEIOUaeiou]” regular expression, which matches with any vowel alphabet.
Java program to delete vowels from string using replaceAll method

package com.tcc.java.programs;
 
import java.util.Scanner;
 
/**
 * Java Program to Delete Vowels from String
 */
public class DeleteVowels {
    public static void main(String args[]) {
        String str, output;
        Scanner scanner = new Scanner(System.in);
 
        System.out.println("Enter a String");
        str = scanner.nextLine();
 
        // Deleting Vowel alphabets from input
        // string using replaceAll method
        output = str.replaceAll("[AEIOUaeiou]", "");
 
        System.out.println("Output String\n" + output);
    }
}

Output

Enter a String
BTechGeeks
Output String
TchCrshCrs
Enter a String
Apple
Output String
ppl