Java String Split splitDigits(long input)

Here you can find the source of splitDigits(long input)

Description

Converts an integer into an Integer array that has individual digits

License

Apache License

Parameter

Parameter Description
input The number for which digits need to be collected

Return

Array of Integer that represent all digits that make the number, in same order, i.e. 123 = {1,2,3}

Declaration

static ArrayList<Integer> splitDigits(long input) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    /**//  ww  w  .  j  ava  2s  . com
     * Converts an integer into an Integer array that has individual digits
     * 
     * @param input
     *            The number for which digits need to be collected
     * @return Array of Integer that represent all digits that make the number,
     *         in same order, i.e. 123 = {1,2,3}
     */
    static ArrayList<Integer> splitDigits(long input) {
        ArrayList<Integer> digits = new ArrayList<Integer>();

        String digitsString = Long.toString(input);
        for (int i = 0; i < digitsString.length(); i++) {
            String subStr = digitsString.substring(i, i + 1);
            digits.add(Integer.parseInt(subStr));
        }

        return digits;
    }
}

Related

  1. splitBreaks(String text)
  2. splitByTypeAndName(final String s)
  3. splitCamelback(String s)
  4. splitCQLStatements(String source)
  5. splitDateText(String text)
  6. splitDomains(String domains)
  7. splitElements(String values)
  8. splitEx(String str, String spilter)
  9. splitFields(String fieldsString, int minNum)