Java examples for java.lang:String Search
Will return number of consonants in given string 'str'
//package com.java2s; public class Main { /** String containing all ascii-consonants */ public static final String CONSONANTS = "bBcCdDfFgGhHjJkKlLmMnNpPqQrRsStTvVwWxXzZ"; /** Will return number of consonants in given string 'str' * @param str string where you want to count consonants * @return number of consonants in string 'str' */ public static int getNumberOfConsonants(String str) { return getNumberOfXXX(str, CONSONANTS); }// ww w. j ava2s . c o m /** Used only internally by methods numberOfVowels and numberOfConsonants, * for purpose of avoiding redundant code */ private static int getNumberOfXXX(String str, String charGroup) { int num = 0; for (char letter : str.toCharArray()) { if (charGroup.contains(Character.toString(letter))) num += 1; } return num; } }