The immediate problem is due to you using <= temp.length() instead of < temp.length(). However, you can achieve this a lot more simply. Even if you use the string approach, you can use:

String temp = Integer.toString(guess);
int[] newGuess = new int[temp.length()];
for (int i = 0; i < temp.length(); i++)
{
    newGuess[i] = temp.charAt(i) - '0';
}

You need to make the same change to use < newGuess.length() when printing out the content too - otherwise for an array of length 4 (which has valid indexes 0, 1, 2, 3) you'll try to use newGuess[4]. The vast majority of for loops I write use < in the condition, rather than <=.

Answer from Jon Skeet on Stack Overflow
๐ŸŒ
sebhastian
sebhastian.com โ€บ int-to-int-array-java
How to convert Java Integer to Int Array instance | sebhastian
July 8, 2021 - Then create a new int[] instance and use the value of String.length() method as the size of the array ยท Use a for loop to put each String character inside the array
๐ŸŒ
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.
๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2013 โ€บ 05 โ€บ how-to-convert-list-of-integers-to-int-array-java-example-tips.html
How to Convert List of Integers to Int Array in Java - Example
Though it sound simple, there is no straight forward way to convert a list of Integer object to int array in Java. Only way to do this conversion is by using Java 1.5 foreach loop or ArrayUtils from Apache commons.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ arrays-in-java
Arrays in Java - GeeksforGeeks
We can use array literals to initialize an array when declaring it. In this case, the new keyword is not required- ... The length of this array determines the length of the created array. When an array is declared and initialized in the same statement, Java allows the array initializer syntax without explicitly writing new int[].
Published: 1 month ago
Find elsewhere
๐ŸŒ
Quora
quora.com โ€บ How-do-I-convert-int-to-int-array-of-digts
How to convert int to int [] (array of digts) - Quora
Answer (1 of 12): Well, one way to do that is to turn the int into a string first, then loop through each character, converting them back to integers and sticking them in an arrayโ€”like splitting the number into its digits step by step. Let me break this down.
๐ŸŒ
YouTube
youtube.com โ€บ jakubication
How To Convert Int To Array In Java - YouTube
How To Convert Int To Array In Java? This video will answer how to convert an integer to an array of its digits in Java. The process taken in this video is f...
Published: March 24, 2024
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ java โ€บ how do i declare and initialize an array in java?
Declare and Initialize Arrays in Java with Examples | Sentry
The int[] myArray says that we want to declare a new variable called myArray that has the type of an array of integers.
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ java โ€บ java-array โ€บ java-array-of-integers
Java Int Array
November 23, 2020 - Java Integer Array is a Java Array that contains integers as its elements. Elements of no other datatype are allowed in this array. In this tutorial, we will learn how to declare a Java Int Array, how to initialize a Java Int Array, how to access elements of it, etc.
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ tutorial โ€บ java โ€บ nutsandbolts โ€บ arrays.html
Arrays (The Javaโ„ข Tutorials > Learning the Java Language > Language Basics)
The three int arguments specify the starting position in the source array, the starting position in the destination array, and the number of array elements to copy.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2022 โ€บ 09 โ€บ convert-integer-list-to-int-array-in-java
Convert Integer List to int Array in Java
September 23, 2022 - Convert Stream<Integer> to int array using toArray() method. import java.util.*; class JavaExample { public static void main(String[] args) { // List of Integer type List<Integer> arrList = new ArrayList<>(); arrList.add(1); arrList.add(3); arrList.add(5); arrList.add(7); arrList.add(9); ...
๐ŸŒ
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.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ java โ€“ convert int[] to integer[] example
Java โ€“ Convert int[] to Integer[] example | mkyong.com
February 22, 2014 - To save you time, uses the ArrayUtils class from the Apache common library, it does the same thing. ... package com.mkyong.test; import org.apache.commons.lang3.ArrayUtils; public class ArrayConvertExample { public static void main(String[] args) { int[] obj = new int[] { 1, 2, 3 }; Integer[] newObj = ArrayUtils.toObject(obj); System.out.println("Test toObject() - int -> Integer"); for (Integer temp : newObj) { System.out.println(temp); } Integer[] obj2 = new Integer[] { 4, 5, 6 }; int[] newObj2 = ArrayUtils.toPrimitive(obj2); System.out.println("Test toPrimitive() - Integer -> int"); for (int temp : newObj2) { System.out.println(temp); } }
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-convert-integer-list-to-int-array-117397
Java Integer List to Int Array Conversion | Programming Tutorials | LabEx
In this step, we'll learn our first method to convert an Integer List to an int array using Java's Stream API.
๐ŸŒ
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 - From the traditional String.split() and Integer.parseInt() approach to more modern Java Streams and safer validation strategies, each method offers flexibility depending on the formatting and reliability of the input data. We also demonstrated how to handle multiple delimiters and filter out invalid values to ensure accurate conversions. This was a quick guide on how to split a string into an int array in Java.