如何在java中基于整数拆分String并返回String Array

时间:2017-04-21 11:52:30

标签: java arrays string split

我有这样的刺痛:

String str = "Aseff1deffre78ijnntke909nnkdhfkk9kshgfks2"; 

我想将此字符串拆分为读取时发生整数的字符串  将拆分字符串存储在字符串数组

2 个答案:

答案 0 :(得分:1)

请尝试以下方法:

 public static String[] splitBasedOnInteger(String str) {
        String str2[] = str.split("\\d+");
        for (String s : str2) {
            System.out.println(s);
        }
        return str2;

答案 1 :(得分:0)

    Pattern p = Pattern.compile("[A-Za-z]+");
    Matcher m = p.matcher("Aseff1deffre78ijnntke909nnkdhfkk9kshgfks2");
    List<String> resultList = new ArrayList<String>();
    while (m.find()) {
        resultList.add(m.group());
    }
    String[] arr = resultList.toArray(new String[resultList.size()]);