In this tutorial we will see how to remove vowels from String in java.
We will use String’s replaceAll() method to remove vowels from 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 StringOperator { public static void main(String args[]) { String str1, str2; Scanner scan = new Scanner(System.in); System.out.print("Enter a String : "); str1 = scan.nextLine(); str2 = str1.replaceAll("[aeiouAEIOU]", ""); System.out.print("All Vowels Removed Successfully..!!\nNew String is : "); System.out.print(str2); } } |
Output:
Enter a String : Java2Blog
All Vowels Removed Successfully..!!
New String is : Jv2Blg
All Vowels Removed Successfully..!!
New String is : Jv2Blg
That’s all about removing vowels from String.
Join Our News Letter – Stay Updated
Subscribe to Awesome Java Content.