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.
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.
The post Java program to remove vowels from String appeared first on Java2Blog.