Converting string into array of ints ex String st = “1 2 3 4 5” into ar=[1,2,3,4,5]
问题 I am reading in a string, as an entire line of numbers, separated by spaces, ie ie 1 2 3 4 5 . I want to convert them into an array of integers, so that I can manipulate them. But this code doesn't work. It says incompatible types. String str = br.readLine(); int[] array = new int[4]; StringTokenizer tok = new StringTokenizer(str," ", true); boolean expectDelim = false; int i = 0; while (tok.hasMoreTokens()) { String token = tok.nextToken(); ar[i] = Integer.parseInt(token); i++; } 回答1: If you