Here you can find the source of countCharacters(String str, char chr)
chr
's in str
.
Parameter | Description |
---|---|
str | The string to check for instances of <code>chr</code>. |
chr | The character to check for. |
chr
occurs in str
.
public static int countCharacters(String str, char chr)
//package com.java2s; public class Main { /**/* ww w . ja v a 2 s . co m*/ * Counts the number of <code>chr</code>'s in <code>str</code>. * * @param str * The string to check for instances of <code>chr</code>. * @param chr * The character to check for. * @return The number of times <code>chr</code> occurs in <code>str</code>. */ public static int countCharacters(String str, char chr) { int ret = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == chr) { ret++; } } return ret; } }