I'm new to Java, so apologies if any of this is unclear - I want to convert a list of four-digit integers into a list of integer arrays - i.e if I have an integer that is 4567, I want to convert that into an array of four separate integers [4, 5, 6, 7]. So I want to convert each line/index of the list into it's own array (rather than converting the entire list into an array). I'm currently reading a file that has four-digit integers (each on a new line) and adding them to a list, which is then returning that list - any ideas on how could I code it so that it returns a list of integer arrays instead?
public List <Integer> loadGuesses (String fileName){
List<Integer> loadGuessList = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = reader.readLine()) != null) {
loadGuessList.add(Integer.parseInt(line));
}
} catch (FileNotFoundException f){
System.out.println("File not found - please re-enter with correct file name.");
getPlayerFile();
} catch (IOException e){
System.out.println("Incorrect file name - Please re-enter with correct file name.");
getPlayerFile();
}
return loadGuessList;
}