Here you can find the source of countChar(final String aString, final char aChar)
Parameter | Description |
---|---|
aString | a parameter |
aChar | a parameter |
public static int countChar(final String aString, final char aChar)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 www.isandlatech.com (www.isandlatech.com) * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w .j a va 2 s. co m * ogattaz (isandlaTech) - initial API and implementation *******************************************************************************/ public class Main { /** * * @param aString * @param aChar * @return the number of the searched char int the string */ public static int countChar(final String aString, final char aChar) { if (aString == null) { return -1; } int wCount = 0; int wMax = aString.length(); int wI = 0; while (wI < wMax) { if (aString.charAt(wI) == aChar) { wCount++; } wI++; } return wCount; } }