Answers for "java how to check how many characters in a string"

1

how to test how many of one character is in a string java

int count = string.length() - string.replaceAll("g","").length()
Posted by: Guest on June-02-2020
2

counting the number of characters in a string java

public static void main(String[] args) {
		int wordCount = 0;
		String word = "hill";
		for (char letter = 'a'; letter <= 'z'; letter++) {
			for (int i = 0; i < word.length(); i++) {
				if (word.charAt(i) == letter) {
					wordCount++;
				}
			}
			if (wordCount > 0) {
				System.out.println(letter + "=" + wordCount);
				wordCount = 0;
			}
		}
	}
Posted by: Guest on January-23-2020

Code answers related to "java how to check how many characters in a string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language