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
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java array โ€บ convert int[] to integer[] in java and back to int[]
Convert int[] to Integer[] in Java and Back to int[]
February 10, 2022 - Java has no cast between int[] and Integer[], so to convert int[] to Integer[] we box every element into a new array, most often with Arrays.stream(ints).boxed().toArray(Integer[]::new), and to go back we unbox every element with mapToInt(I...
๐ŸŒ
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
October 2, 2026 - The int[] myArray says that we want to declare a new variable called myArray that has the type of an array of integers.
๐ŸŒ
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.
๐ŸŒ
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); ...
๐ŸŒ
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); } }
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ int-array-java
Java - int Array - Dot Net Perls
int[] alternative = new int[ ... A method can return an array.
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 416619 โ€บ java โ€บ Convert-Integer-List-int-array
Convert Integer List to int array (Beginning Java forum at Coderanch)
September 23, 2008 - Thanks a lot for your messages. So then the only way to do this, is to loop through the list and then add the elements to int array.