- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to check occurrence of each vowel in String
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}
- Related Articles
- Java program to check occurence of each vowel in String
- Java program to check occurrence of each character in String
- Java program to count the occurrence of each character in a string using Hashmap
- Java program to check occurence of each character in String
- Python program to find occurrence to each character in given string
- Python program to check if the given string is vowel Palindrome
- Java Program to Check Whether an Alphabet is Vowel or Consonant
- Python Program to accept string starting with vowel
- Java program to check order of characters in string
- C Program to find minimum occurrence of character in a string
- C Program to find maximum occurrence of character in a string
- Java Program to check the beginning of a string
- Java Program to check the end of a string
- Java program to check string as palindrome
- C++ Program to Check Whether a character is Vowel or Consonant

Advertisements