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

import java.util.TreeMap;
//计算字符串中子串出现的次数
public class Test {
	public static void main(String[] args) {
		TreeMap<Character,Integer > 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));
		}
	}
}

 

posted on 2017-03-09 20:14  LoaderMan  阅读(697)  评论(0编辑  收藏  举报

导航