Hello, I am not sure how to read Integer values from a textfile that has "strings" and "ints" . I want to save strings in an array and int in an array so I can use them later on.
For example, ask for something and output this element.
static void readArray(String fileName) throws FileNotFoundException { Scanner s = new Scanner(new File(fileName)); ArrayList<String> Array = new ArrayList<String>(); ArrayList<Integer> ArrayInt = new ArrayList<Integer>(); // Here my try.. //int j = 0; while(s.hasNextInt()) { ArrayInt.add(s.nextInt()); } Out.println(ArrayInt); }
My Output is: [] but there should be int values in it