Saturday, March 28, 2015

find character uppercase/lowercase count from given text

Find the character upper/lower case occurrence count with simple single line code without iteration in java.

int counta = text.split("(?=[a])").length - 1;

This simple code will find all the lowercase character 'a' from the given text, change the regx for the uppercase . ex 'A'.

sample test code

 * @author Uttesh Kumar T.H.
public class Countchar {

    public static void main(String[] args) {
        String text = "asfasfzxph adsa wetw";
        int counta = text.split("(?=[a])").length - 1;
        System.out.println("count a : "+counta);




Post a Comment