
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to count vowels in a string
Let’s say the following is our string −
String myStr = "Jamie";
Set variable count = 0, since we will be calculating the vowels in the same variable. Loop through every character and count vowels −
for(char ch : myStr.toCharArray()) { ch = Character.toLowerCase(ch); if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { ++count; }
Example
Following is an example to count vowels in a string −
public class Demo { public static void main(String[] args) { String myStr = "Jamie"; int count = 0; System.out.println("String = "+myStr); for(char ch : myStr.toCharArray()) { ch = Character.toLowerCase(ch); if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { ++count; } } System.out.println("Vowels = "+count); } }
Output
String = Jamie Vowels = 3
- Related Articles
- Java Program to count all vowels in a string
- C# Program to count vowels in a string
- C++ Program to count Vowels in a string using Pointer?
- To count Vowels in a string using Pointer in C++ Program
- C# Program to count number of Vowels and Consonants in a string
- Python program to count number of vowels using set in a given string
- Java program to count the number of vowels in a given sentence
- Python program to count the number of vowels using set in a given string
- Python program to count the number of vowels using sets in a given string
- Program to match vowels in a string using regular expression in Java
- Java Program to Count the Number of Vowels and Consonants in a Sentence
- Count and display vowels in a string in Python
- Java Program to count letters in a String
- C Program to count vowels, digits, spaces, consonants using the string concepts
- Java program to count words in a given string

Advertisements