Here you can find the source of countMatches(String string, char find)
public static int countMatches(String string, char find)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 Gabriel Skantze.// w w w . j a va2s .c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Gabriel Skantze - initial API and implementation ******************************************************************************/ public class Main { public static int countMatches(String string, char find) { int count = 0; for (int i = 0; i < string.length(); i++) { if (string.charAt(i) == find) count++; } return count; } }