This article describes the method of java to count the number of repeated characters in strings. Share it for your reference, as follows:
package com;import org.junit.Test;/** * Statistics the number of times a string appears in a number of repeated characters* * @author zdw * */public class StringTest{ @Test public void test() { String s = "fdfaacceeeeeeeeeeegghikkkkkokoooo"; count(s); } public static void count(String str) { // Used to store the number of times az appears int[] nums = new int[26]; for (char i : str.toCharArray()) { // If (i >= 97 && i <= 123) { // Just accumulate in its corresponding index bit nums[i - 97]++; } } for (int i = 0; i < nums.length; i++) { // Only display the occurrence of if (nums[i] != 0) { System.out.println((char) (97 + i) + ":" + nums[i]); } } }}For more information about Java related content, please check out the topics of this site: "Java Data Structure and Algorithm Tutorial", "Summary of Java Operation DOM Node Tips", "Summary of Java File and Directory Operation Tips" and "Summary of Java Cache Operation Tips"
I hope this article will be helpful to everyone's Java programming.