There are a number of ways, one of which would be...

    String ss[] = "123".split("");
    int i = 
            Integer.parseInt(ss[0]) + 
            Integer.parseInt(ss[1]) + 
            Integer.parseInt(ss[2]);
    System.out.println(i);

another would be...

    String s = "123";
    int i = 
            Character.getNumericValue(s.charAt(0)) +
            Character.getNumericValue(s.charAt(1)) +
            Character.getNumericValue(s.charAt(2));
    System.out.println(i);

and still another would be...

    String s = "123";
    int i = 
            s.charAt(0) +
            s.charAt(1) +
            s.charAt(2) - 
            (3 * 48);
    System.out.println(i);

BUT hard coding for 3 numbers isn't very useful beyond this simple case. So how about recursion??

public static int addDigis(String s) {
        if(s.length() == 1)
            return s.charAt(0) - 48;
        return s.charAt(0) - 48 + addDigis(s.substring(1, s.length()));
}

Output for each example: 6

Answer from ChiefTwoPencils on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java numbers › how to split an integer number into digits in java
How to Split an Integer Number Into Digits in Java | Baeldung
January 8, 2024 - So, split() takes the zero-width “character” after any character as the splitter. It might be easier to understand if we use the ‘#’ character to replace the zero-width “character” in the number string: “1#2#3#0#4#5#6#”. Further, ...
Discussions

Split an int into 2-digit chunks and store in an array
It sounds like you are recalling something cleaver, but can't recall the details. Keep it simple and just do something that works. The most important things are that it work and that it is understandable, so don't overthink it. If you aren't sure how to isolate two digits... num % 100 is the last two and num/100 is the rest of the digits. More on reddit.com
🌐 r/javahelp
6
4
January 26, 2022
java - Convert an integer to an array of digits - Stack Overflow
Convert the number to a string → convert the string into an array of characters → convert the array of characters into an array of integers More on stackoverflow.com
🌐 stackoverflow.com
Java- Converting a string of numbers separated by spaces into an array?
You have the right idea. String.split() will return an array of strings. Then, if you want to treat any individual string in that array as an integer you can use Integer.parseInt() . If you want to create an array of integers, just make the array that way. More on reddit.com
🌐 r/learnprogramming
7
4
February 2, 2016
Java - How to reverse and split a number by digit into an array? - Stack Overflow
I'm learning java coming from a ruby background and self-teaching. I am doing a problem that wants a number reversed and listed into an array by digit. Ex 1234 -> [4,3,2,1] In ruby I did this ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Split Java Integer Into Digits - Java Code Geeks
January 4, 2024 - When dealing with integer numbers in Java, there are occasions where it becomes necessary to decompose them into individual digits for diverse calculations or data manipulation purposes. Let us delve into a practical approach to understanding Java Integer Digit Split. Below is an example code snippet in Java that demonstrates how to split an integer into a list of individual digits: package com.javacodegeeks; import java.util.ArrayList; import java.util.List; public class IntegerSplitExample { public static List<Integer> splitToDigits(int number) { List<Integer> digitList = new ArrayList<>();
🌐
W3Docs
w3docs.com › java
Convert an integer to an array of digits - Java
To convert an integer to an array of digits in Java, you can use the toCharArray() method of the String class to convert the integer to a string, and then use the toCharArray() method to convert the string to an array of characters.
🌐
How to do in Java
howtodoinjava.com › home › java array › split an array in java: at an index, in halves or in chunks
Split an Array in Java: At an Index, in Halves or in Chunks
3 weeks ago - To split at index k, we copy the range [0, k) into the first array and [k, length) into the second. Any k from 0 to length is a valid split point, and the edge values give one empty part.
🌐
Reddit
reddit.com › r/javahelp › split an int into 2-digit chunks and store in an array
r/javahelp on Reddit: Split an int into 2-digit chunks and store in an array
January 26, 2022 -

Been stuck on this for a little while. Basically, if I have the int/Integer: 1425273622

I need to split it apart and put it in an array like: [14,25,27,36,22]

I could’ve sworn I learned a way to do something like this (.toString() and substring the first 2 characters at a time, then parseInt()?) but I can’t for the life of me get the right functions calls.

Top answer
1 of 5
3
It sounds like you are recalling something cleaver, but can't recall the details. Keep it simple and just do something that works. The most important things are that it work and that it is understandable, so don't overthink it. If you aren't sure how to isolate two digits... num % 100 is the last two and num/100 is the rest of the digits.
2 of 5
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
Find elsewhere
🌐
Reddit
reddit.com › r/learnprogramming › java- converting a string of numbers separated by spaces into an array?
r/learnprogramming on Reddit: Java- Converting a string of numbers separated by spaces into an array?
February 2, 2016 -

For example, I have String input which will look something like "5 6 6" but I need it to be converted into an array. What is the easiest way to do this? I have messed around with .split and .parseInt but have not come to any solid conclusions. Thanks!

🌐
Baeldung
baeldung.com › home › java › java string › splitting string into an int array in java
Splitting String into an int Array in Java | Baeldung
February 14, 2026 - In addition to that, strings are objects of the java.lang.String class. This class has many methods to work with strings. ... In the above example, we’ve a string containing a list of numbers. These numbers are separated by commas. It’s important to note that 10 is a string here, not an integer. Thus, we can’t directly use it in any arithmetic operations. So, we’ll split this string into individual elements. We then convert them into integers for use within an array.
🌐
W3docs
w3docs.com › home › code snippets › java › convert an integer to an array of digits
Convert an integer to an array of digits | W3docs
To convert an integer to an array of digits in Java, you can use the toCharArray() method of the String class to convert the integer to a string, and then use the toCharArray() method to convert the string to an array of characters.
🌐
Reddit
reddit.com › r/learnprogramming › [java] separate numbers of an integer, then add them together.
r/learnprogramming on Reddit: [Java] Separate numbers of an integer, then add them together.
July 17, 2014 -

Not sure where to go with this one. I've tried a couple methods, like converting a string to a char array and outputting that, although it prints the number back without spaces, which isn't what I need.

I know how to do the addition of each individual numbers using modulo, but outputting the individual numbers of the int, in order, is the part tripping me up.

I figured putting the numbers into an array would work, but since Java doesn't allow for dynamically changing the length of an array, I'm not sure how efficient that would have been. Also, since I do need the int output for the sake of adding the numbers together, I'm lost as to how to do this.

It should look like this:

input : 222294

output : 2 2 2 2 9 4

addition output : 21

I can do the last part no problem, but getting the numbers IN ORDER and separated is difficult.

Also, since I can't control what the number is or how many digits it is, that is also a problem.

What would be an efficient way to get them separated in order?

🌐
Java Code Geeks
javacodegeeks.com › home › core java
How to Split a String into an Int Array in Java - Java Code Geeks
November 10, 2025 - In this example, the regular expression [,; ]+ tells Java to split the string wherever a comma, semicolon, or space appears. Each substring is then converted into an integer, giving you a clean array of numbers even when the input isn’t uniformly ...
🌐
Stack Overflow
stackoverflow.com › questions › 15421896 › trying-to-split-a-single-int-number-into-separate-numbers-for-an-array
java - Trying to split a single int number into separate numbers for an array - Stack Overflow
A multi-digit number is only multi-digit in the sense that the String representation requires multiple digits. With that in mind, your best option will be to use toString and pull out the individual components as Integers.
🌐
Stack Overflow
stackoverflow.com › questions › 36696017 › splitting-digits-of-a-number-into-an-integer-array
java - Splitting Digits of a Number into an Integer Array - Stack Overflow
April 18, 2016 - This code simply just gets the length of the number, so I can make the array the appropriate length. int[] numberSplitted = new int[counter]; int divisor = (int)Math.pow(10, (counter-1)); // = 1000 in this case int locationInArray = 0; while(divisor ...
🌐
javathinking
javathinking.com › blog › splitting-string-into-an-int-array-in-java
Splitting String into an int Array in Java — javathinking.com
In this blog post, we explored different ways to split a string into an integer array in Java. We learned how to use the split() method with a loop and the Java Stream API. We also discussed error handling and best practices to ensure a robust ...
🌐
Techie Delight
techiedelight.com › home › java › split an array into two parts in java
Split an array into two parts in Java | Techie Delight
July 7, 2026 - We can make use of this method to split array, as shown below: ... In both approaches discussed above, we manually allocate memory for both arrays. Java Collection Framework also provides one method, copyOfRange(), that copies the specified range of the source array into a new array and returns that array.
🌐
YouTube
youtube.com › watch
Java - Split a string into an array | Arrays in Java - YouTube
If you have a string in Java, and you want to split it (explode it) into an array of smaller strings, how can you go about doing that? In this lecture we'll ...
Published: April 27, 2019