Java String Match Count countMatches(String string, char find)

Here you can find the source of countMatches(String string, char find)

Description

count Matches

License

Open Source License

Declaration

public static int countMatches(String string, char find) 

Method Source Code

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

Related

  1. countMatches(String str, String sub)
  2. countMatches(String str, String sub)
  3. countMatches(String str, String sub)
  4. countMatches(String str, String sub)
  5. countMatches(String str, String sub)
  6. countMatches(String string, char toMatch)
  7. countMatches(String string, String other)
  8. countMatches(String theString, String... sep)
  9. countMatches(String[] query, String[] entry)