How convert an int into an Array number by number

Artem :

I have one number, for example "1256", how can I convert it into an Array?

Actually, I use a constructor of class where I stock it.

public SecretBlock(int numbersToArray) {
    this.arrayOfNumbers = new int[AMOUNT];
    for (int i = AMOUNT - 1; i >= 0; i--) {
        this.arrayOfNumbers[i] = numbersToArray % 10;
        numbersToArray /= 10;
    }
}

Is there any fine/ adequate solution that may use Java 8 Stream?

Eugene :
 int[] result = String.valueOf(numbersToArray)
            .chars()
            .map(Character::getNumericValue)
            .toArray();

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=475434&siteId=1