package guwa;
public class Letter {
private String name;
private int count;
public Letter() {
}
public Letter(String name, int count) {
super();
this.name = name;
this.count = count;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
package guwa;
import java.util.HashMap;
import java.util.Map;
public class TestLetter {
public static void main(String[] args) {
String str="a a ab abc ab abc b";
String[] arr=str.split(" ");
Map<String,Letter> map=new HashMap<String,Letter>();
for(String temp:arr){
Letter col=null;
if( null==(col=map.get(temp)) ){
col=new Letter();
col.setCount(1);
map.put(temp, col);
}else{
col.setCount(col.getCount()+1);
map.put(temp, col);
}
}
for(String key:map.keySet()){
System.out.println(key+"->"+map.get(key).getCount());
}
}
}