将数字拼音词分隔开(shu3jia4------shu3 jia4)

本人新手刚入职公司,负责人给我安排了一个小的任务。将数字拼音分隔开,如:shu3jia4------shu3   jia4   ,当时想用字符串截取的方法写,后来觉得太麻烦,最终想到用数组的方式写,先把他记下已被下次使用。

话不多说贴代码(大体思路就是)

int index=0;
int count=0;
String[] arr= word.split("");
ArrayList<String> words=new ArrayList<String>();
ArrayList<Integer> wordsIndex=new ArrayList<Integer>();
ArrayList<String> last=new ArrayList<String>();
HashSet<String> number=new HashSet<String>() {{
add("0");
add("1");
add("2");
add("3");
add("4");
add("5");
add("6");
add("7");
add("8");
add("9");

}};
for(int i=0;i<arr.length;i++)
{
if(number.contains(arr[i])) {
//System.out.println(i);
wordsIndex.add(i);
}

}
String tt=word.substring(0,wordsIndex.get(0)+1);
last.add(tt);
//System.out.println(tt);
for(int i=0;i<wordsIndex.size()-1;i++) {

last.add(word.substring(wordsIndex.get(i)+1,wordsIndex.get(i+1)+1));
}

 

posted @ 2018-03-25 20:13  ofo小白  阅读(551)  评论(0编辑  收藏  举报