There is a string containing Chinese characters, English characters and numeric characters, please count and print out the number of each character.

1. There is a string containing Chinese characters, English characters and numeric characters, please count and print out the number of each character.

 

The set defined by the Map interface, also known as lookup table, is used to store so-called "Key-Value" mapping pairs. Key can be regarded as the index of Value, and the object as Key cannot be repeated in the collection.

 

import java.util.HashMap;
import java.util.Map;


public class Demo {
	  public static void main(String[] args) throws Exception{
		 String content="China ABCawpl8394 America";
		 Map<Character,Integer> map=new HashMap();
		 char[] arryChar=content.toCharArray();
		 for(char c:arryChar){
			 if(map.containsKey(c)){
				 map.put(c, map.get(c)+1);
			 }else{
				 map.put(c, 1);
			 }
		 }
		 System.out.println(map);
	  }

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981170&siteId=291194637