This example describes a method that repeats the number of occurrences of characters in a Java statistics string. Share to everyone for your reference, specific as follows:
package com;
Import Org.junit.Test;
/**
* Statistics The number of occurrences of a repeated character of a string * * @author ZDW * * */public
class stringtest
{
@Test
public void Test ()
{
String s = ' fdfaacceeeeeeeeeeeegghikkkkkoooo ';
Count (s);
}
public static void Count (String str)
{
//The number of times A-Z appears to be stored
int[] nums = new int[26];
for (char I:str.tochararray ())
{
//within the range of letters
if (i >= && i <= 123)
{
//in its corresponding index Bit to add to the
nums[i-97]++;
}
for (int i = 0; i < nums.length i++)
{
//Show only
if (Nums[i]!= 0)
{
System.out.println (char ) (+ i) + ":" + Nums[i]);}}}
More about Java-related content readers can view the site topics: "Java Data structure and algorithm tutorial", "Java Operation DOM node skills summary", "Java file and directory operation tips Summary" and "Java Cache operation Tips"
I hope this article will help you with Java programming.