Here you can find the source of countChar(StringBuffer sb, char ch)
Parameter | Description |
---|---|
sb | The string buffer. |
ch | The character. |
public static int countChar(StringBuffer sb, char ch)
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /** Count occurrences of character in string buffer. *// w ww . ja v a 2s . co m * @param sb The string buffer. * @param ch The character. * * @return Number of occurrences of ch in sb. */ public static int countChar(StringBuffer sb, char ch) { int result = 0; for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == ch) result++; } return result; } }