private?static?void?test()?{
String?ss?=?"Ae5a2sd35s4eEe62a35e1ao";
Pattern?p=Pattern.compile("(\\d+)");
//?使用正則表達式取出所有數(shù)字
Matcher?m=p.matcher(ss);
Map<Integer,?Integer>?cc?=?new?HashMap<Integer,?Integer>();
//?統(tǒng)計所有數(shù)字的出現(xiàn)次數(shù)。數(shù)字為key,出現(xiàn)次數(shù)為value存入map
while(m.find()){
int?i?=?Integer.valueOf(m.group(1));
if(cc.containsKey(i))?{
cc.put(i,?cc.get(i)?+?1);
}else?{
cc.put(i,?1);
}
??}
//?找到map中最大的value,即最大的出現(xiàn)次數(shù),它對應的key則為出現(xiàn)最多的數(shù)字
//?可能不止一個,使用循環(huán)找出所有出現(xiàn)最多的數(shù)字。如果都只出現(xiàn)1次則全部找出
int?max?=?Collections.max(cc.values());
for(Entry<Integer,?Integer>?entry?:?cc.entrySet())?{
if(entry.getValue()?==?max)?{
System.out.println(entry.getKey()?+
"為出現(xiàn)最多的數(shù),出現(xiàn)次數(shù)為"?+?entry.getValue()?+
".?和為"?+?entry.getKey()?*?entry.getValue());
}
}
}