Here you can find the source of countCharInString(String s, char c)
public static int countCharInString(String s, char c)
//package com.java2s; /**//from ww w.j a v a 2s . c om * Title: efa - elektronisches Fahrtenbuch f?r Ruderer * Copyright: Copyright (c) 2001-2011 by Nicolas Michael * Website: http://efa.nmichael.de/ * License: GNU General Public License v2 * * @author Nicolas Michael * @version 2 */ public class Main { public static int countCharInString(String s, char c) { int n = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == c) { n++; } } return n; } public static int countCharInString(String s, String c) { int n = 0; int pos; while ((pos = s.indexOf(c)) >= 0) { n++; s = s.substring(pos + c.length()); } return n; } }