Java String Char Count countChar(String s, char c)

Here you can find the source of countChar(String s, char c)

Description

Count the number of times a given character occurs in a String:

License

Open Source License

Declaration


public static int countChar(String s, char c) 

Method Source Code

//package com.java2s;

public class Main {
    /** Count the number of times a given character occurs in a String: */
    //@ ensures \result>=0;
    public static int countChar(/*@non_null*/String s, char c) {
        int count = 0;
        int start = 0;

        while ((start = s.indexOf(c, start) + 1) != 0)
            count++;/*from  w  w  w. jav a2  s.c om*/

        return count;
    }
}

Related

  1. countChar(String s, char c)
  2. countChar(String s, char c)
  3. countChar(String sql, int end)
  4. countChar(String src, char c)