我希望将第5行中打印的值插入到整数数组中。 该文件包含整数值和字符串值。
****我还在学习过程中**** 对不起,我改变了一下这个问题。 谢谢将值插入到字符串类型列表中的整数数组中
File f = new File("SampleInput.txt");
try{
ArrayList<String> lines = get_arraylist_from_file(f);
for(int x =23; x < lines.size(); x++){
System.out.println(lines.get(x));
**enter code here**
}
}
catch(Exception e){
System.out.println("File not found!!!!");
}
}
public static ArrayList<String> get_arraylist_from_file(File f)
throws FileNotFoundException {
Scanner s;
ArrayList<String> list = new ArrayList<String>();
s = new Scanner(f);
while (s.hasNext()) {
list.add(s.next());
}
s.close();
return list;
}
为什么不使用List而不是Array? – basic