代码实现:计算字符串中子串出现的次数

import java.util.TreeMap;
//计算字符串中子串出现的次数
public class Test {
	public static void main(String[] args) {
		TreeMap tm = new TreeMap<>();
		String s = "nalskjoiw eaoijajkwlcx aksoiaa lzndoiawlksnnz";
		char[] chs = s.toCharArray();
		for (char c : chs) {
			if(!tm.containsKey(c)){
				
				tm.put(c, 1);
			}else{
				tm.put(c, tm.get(c)+1);
			}
		}
		for (Character c : tm.keySet()) {
			System.out.println(c + "---" +tm.get(c));
		}
	}
}

 

转载于:https://www.cnblogs.com/loaderman/p/6527578.html

你可能感兴趣的:(代码实现:计算字符串中子串出现的次数)