data.txt 文件包含:
Manyana, Michael, 30
Henderson, Marge, 22
Striker, Nancy, 32
Johnson, Fred, 12
Ryan, Renee, 22
我想知道如何只显示名字并将其存储到一个新数组中。如何只选择名字?例如,
Manyana
Henderson
Striker
Johnson
Ryan
提前致谢。
import java.io.*;
import java.util.Scanner;
public class multipleArray {
private static Scanner file;
public static String[] array = new String[500];
public static void main(String[] args) throws FileNotFoundException {
File myfile = new File("data.txt");
file = new Scanner (myfile);
Scanner s = file.useDelimiter(",");
int i = 0;
while (s.hasNext()) {
i++;
array[i] = s.next();
}
for(int j=0; j<array.length; j++) {
if(array[j] == null)
;
else
System.out.print(array[j]);
}
}