[java] How to get the separate digits of an int number?

in Java, this is how you can separate digits from numbers and store them in an Array.

public static void main(String[] args) {
        System.out.println("Digits Array:: "+Arrays.toString(getNumberArr(1100)));
}

private static Integer[] getNumberArr(int number) {
    //will get the total number of digits in the number
    int temp = number;
    int counter = 0;

    while (temp > 0) {
        temp /= 10;
        counter++;
    }
    //reset the temp
    temp = number;

    // make an array
    int modulo;     //modulo is equivalent to single digit of the number.
    Integer[] numberArr = new Integer[counter];
    for (int i = counter - 1; i >= 0; i--) {
        modulo = temp % 10;
        numberArr[i] = modulo;  
        temp /= 10;
    }

    return numberArr;
}

Output:

Digits Array:: [1, 1, 0, 0]

Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to integer

Python: create dictionary using dict() with integer keys? How to convert datetime to integer in python Can someone explain how to append an element to an array in C programming? How to get the Power of some Integer in Swift language? python "TypeError: 'numpy.float64' object cannot be interpreted as an integer" What's the difference between integer class and numeric class in R PostgreSQL: ERROR: operator does not exist: integer = character varying C++ - how to find the length of an integer Converting binary to decimal integer output Convert floats to ints in Pandas?

Examples related to modulo

'MOD' is not a recognized built-in function name Modulo operation with negative numbers Can't use modulus on doubles? Assembly Language - How to do Modulo? How to use mod operator in bash? How can I calculate divide and modulo for integers in C#? What is the result of % in Python? How does java do modulus calculations with negative numbers? Integer division with remainder in JavaScript? How to code a modulo (%) operator in C/C++/Obj-C that handles negative numbers