Java Online Compiler
Example: Remove Vowels using replaceAll in Java
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Remove Vowels using replaceAll import java.util.Scanner; // Main class containing the entry point of the program public class Main { public static void main(String[] args) { // Step 1: Define the input string String originalString = "Programming Is Fun"; System.out.println("Original String: " + originalString); // Step 2: Define the regular expression for vowels and replace // "[aeiouAEIOU]" matches any single lowercase or uppercase vowel. // The replaceAll method substitutes all matched characters with an empty string "". String stringWithoutVowels = originalString.replaceAll("[aeiouAEIOU]", ""); // Step 3: Print the result System.out.println("String without Vowels: " + stringWithoutVowels); // Example with user input Scanner scanner = new Scanner(System.in); System.out.print("\nEnter another string: "); String userInput = scanner.nextLine(); String processedInput = userInput.replaceAll("[aeiouAEIOU]", ""); System.out.println("Processed String: " + processedInput); scanner.close(); } }
Output
Clear
ADVERTISEMENTS