How To Count Letters in String in Java
In the last post, we have discussed how to find character or character position in string in java with simple examples and now here we are going to create a simple example for how to count letters in java string with examples.
So let's start with a useful example for finding the number of letters in a given java String.
The below example gives you a total number of letters count in a given java string i.e (given string is "sun45tt" and letters in this give string is suntt i.e 5).
Java Program to Count Letters in String
class LettersCountInString
{
public static void main(String args[])
{
String str = "sun45tt";
int count = 0;
for(int i = 0; i<str.length(); i++)
{
if(Character.isLetter(str.charAt(i)))
{
count++;
}
}
System.out.println(count);
}
}
Output: 5
Here we discussed, how to write a java program to count letters in string with a simple example.
This blog is so cool. I am learning Java Training online. This blogs helps me find out better understanding about salesforce training. Thank you for this blog!
ReplyDeleteVery good content post. Please continue to post such awesome posts. It was so attractive reading the article and it helped me improve my knowledge as an updated one. Thanks a lot.
ReplyDeleteJava Certification Training in Electronic City
Advance Java Certification Training in Electronic City
This is really a helpful blog I am really impressed with your work, keep it up the good work
ReplyDelete1Z0-900: Java EE 7 Application Developer
This is really a helpful blog I am really impressed with your work, keep it up the good work
ReplyDelete1Z0-900: Java EE 7 Application Developer
This Article is amazing. I am learning Java Training online from Fullstack Guru. This blog helps me find out a better understanding of Java Concepts. Thank you!
ReplyDelete