日期:2014-05-20 浏览次数:20725 次
public static void main(String[] args) {
String testStr = "addcbbs";
byte[] strBytes = testStr.getBytes();
for (byte b : strBytes) {
System.out.println((char)(b));
}
Map map = new HashMap();
int temp = 1;
for(int i = 0; i<strBytes.length; i++ ){
byte b = strBytes[i];
String charStr = (char)b+"";
Integer num = (Integer) map.get(charStr);
if(num != null){//不是第一次
temp = ++num;
}else{//第一次
map.put(charStr, temp);
}
if(map.containsKey(charStr)){
map.put(charStr, temp);
}
temp = 1;
}
System.out.println("-------------------");
Set key = map.keySet();
for (Iterator it = key.iterator(); it.hasNext();) {
String b = (String) it.next();
System.out.println(b+"--"+map.get(b));
}
}
import java.util.HashMap;
import java.util.Map;
public class RemoveMostWords
{
public static void main(String[] args)
{
String str = "addcbbs";
System.out.println("处理前的字符串:" + str);
String deelStr = removeMostWords(str);
System.out.println("处理后的字符串:" + deelStr);
}