
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check Occurrence of Each Vowel in String using Java
To count occurence of vowels in a string again use Map utility of java as used in calculating occurence of each character in string.Put each vowel as key in Map and put initial value as 1 for each key.Now compare each character with key of map if a character matches with a key then increase its corresponding value by 1.
Example
public class OccurenceVowel { public static void main(String[] args) { String str = "AEAIOG"; LinkedHashMap<Character, Integer> hMap = new LinkedHashMap(); hMap.put('A', 0); hMap.put('E', 0); hMap.put('I', 0); hMap.put('O', 0); hMap.put('U', 0); for (int i = 0; i <= str.length() - 1; i++) { if (hMap.containsKey(str.charAt(i))) { int count = hMap.get(str.charAt(i)); hMap.put(str.charAt(i), ++count); } } System.out.println(hMap); } }
Output
{A=2, E=1, I=1, O=1, U=0}
Advertisements