Java String Split splitIntegerFromString(String str)

Here you can find the source of splitIntegerFromString(String str)

Description

split Integer From String

License

Open Source License

Declaration

public static List<Integer> splitIntegerFromString(String str) 

Method Source Code

//package com.java2s;
/*/*from  w w w  .  j a  v a  2s  . c o m*/
 * Copyright 1998-2012 360buy.com All right reserved. This software is the confidential and proprietary information of
 * 360buy.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with 360buy.com.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {

    public static List<Integer> splitIntegerFromString(String str) {
        List<Integer> integerList = null;
        if (null == str) {
            return integerList;
        }
        integerList = new ArrayList<Integer>();
        String numDict = "0123456789";
        char[] strChars = str.toCharArray();
        StringBuffer sbuffer = new StringBuffer();
        for (char ch : strChars) {
            if (numDict.indexOf(ch) != -1) {
                sbuffer.append(ch);
            } else {
                if (sbuffer.length() > 0) {
                    integerList.add(Integer.valueOf(sbuffer.toString()));
                    sbuffer.setLength(0);
                }
                continue;
            }
        }
        if (sbuffer.length() > 0) {
            integerList.add(Integer.valueOf(sbuffer.toString()));
            sbuffer.setLength(0);
        }

        return integerList;
    }
}

Related

  1. splitHTMLTags(final String string)
  2. splitIdKeyConfig(String config)
  3. splitInitialItems(final String text)
  4. splitInput(String cliInput)
  5. splitIntArray(final String iInput)
  6. splitIntegerPerDigit(int i)
  7. splitIntoPackages(String stmt)
  8. splitIntoPairs(String subDirName)
  9. splitInts(String str)