masse兄弟,你的代码可以改成这样吗,
public static void main(String[] args) throws Exception {
// 你要解析的文章
String s = "one,two, three one !mydear four , five";
// 正则表达式,可以添加你自己的分隔符
Pattern p = Pattern.compile("[,.!;?\\s]+");
String[] result =p.split(s);
Map map = new HashMap();
for (int i=0; i<result.length; i++){
int count = 0;
if(map.get(result[i])!=null) count = ((Integer)map.get(result[i])).intValue();
map.put(result[i],new Integer(++count));
}
List list = new ArrayList();
list.addAll( map.keySet());
for(int i=0;i<map.size();i++){
System.out.println((String) list.get(i) + ":" + map.get((String) list.get(i)));
}
}
public class Main {
public static void main(String[] args) throws Exception {
// 你要解析的文章
String s = "one,two, three one !mydear four , five";
// 正则表达式,可以添加你自己的分隔符
Pattern p = Pattern.compile("[,.!;?\\s]+");
String[] result =p.split(s);
Map map = new HashMap();
for (int i=0; i<result.length; i++){
int count = 0;
if(map.get(result[i])!=null) count = ((Integer)map.get(result[i])).intValue();
map.put(result[i],new Integer(++count));
}
public class Main {
public static void main(String[] args) throws Exception {
Pattern p = Pattern.compile("[,.!\\s]+");
Set set = new HashSet();
String[] result =
p.split("one,two, three one !mydear four , five");
for (int i=0; i<result.length; i++)
set.add(result[i]);
// set里面存的字符串就是你要的字符串
}
}