Replace Vowels with *

This program replaces vowels with *.

Problem Statement

Write a Java program to replace vowels in string with *.

Source Code

1 public class RegexReplaceVowels {
2 public static void main(String[] args) {
3 System.out.println("Eduinq Regex Replace Vowels");
4 String str="EduinqString";
5 String result=str.replaceAll("[AEIOUaeiou]","*");
6 System.out.println("After replacement: "+result);
7 }
8 }

Program Output

Eduinq Regex Replace Vowels
After replacement: *d**nqStr*ng

Explanation

The character class [AEIOUaeiou] matches any vowel regardless of case, and replaceAll() substitutes each matched vowel with an asterisk, demonstrating targeted character replacement.

Quick Links to Explore