分字

 

===========方案一====================

/**
* 拆分成单个字
*/
public static List<String> splitWord(String str) {
  if(str == null || "".equals(str.trim())) {
    return null;
  }
  List<String> listStr = new ArrayList<String>();
  for (int i = 0; i < str.length(); ++i) {
    listStr.add(Character.toString(str.charAt(i)));
  }
  return listStr;
}

===========方案二=====================

public class PatternTest {

public static void main(String[] args) {

String s = new String("我是中国人");

System.out.println(checkChinese(s));

}

public static String checkChinese(String str){

String sb = new String();

Pattern pattern = Pattern.compile("[\u3007\u4E00-\u9FCB\uE815-\uE864]");//只匹配一个中文字符

Matcher matcher = pattern.matcher(str);

while(matcher.find()){

sb += matcher.group()+";";

}

return sb.toString();

}

}

posted @ 2017-04-07 18:58  dcxmaozi  阅读(236)  评论(0编辑  收藏  举报