In this example, I have shared How to remove vowels from a String using Java.
Given a string, remove the vowels from the string and print the string without vowels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import java.util.Arrays; import java.util.List; class removeVowelsFromString { static String remVowel(String str) { Character vowels[] = {'a', 'e', 'i', 'o', 'u','A','E','I','O','U'}; List<Character> al = Arrays.asList(vowels); StringBuffer sb = new StringBuffer(str); for (int i = 0; i < sb.length(); i++) { if(al.contains(sb.charAt(i))){ sb.replace(i, i+1, "") ; i--; } } return sb.toString(); } public static void main(String[] args) { String str = "I am a student"; System.out.println(remVowel(str)); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.