Java String Char Count countChar(StringBuffer sb, char ch)

Here you can find the source of countChar(StringBuffer sb, char ch)

Description

Count occurrences of character in string buffer.

License

Open Source License

Parameter

Parameter Description
sb The string buffer.
ch The character.

Return

Number of occurrences of ch in sb.

Declaration


public static int countChar(StringBuffer sb, char ch) 

Method Source Code

//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;
    }
}

Related

  1. countChar(String str, char reg)
  2. countChar(String string, char c, int pos, boolean forwards)
  3. countChar(String string, String c)
  4. countChar(String text, char c)
  5. countChar(String text, char ch)
  6. countChars(String data)
  7. countChars(String input)
  8. countChars(String s, boolean countDigits, boolean countLetters, boolean countOthers)
  9. countChars(String s, char c)