【发布时间】:2015-02-11 06:50:05
【问题描述】:
我有一个从列表中挑选项目的代码,我有一个扫描仪检查文件(其中包含电影,然后每行有演员)并将电影添加到数组中。我将如何使它添加到数组列表中的每一部电影也存储在线上的演员?例如: 每一行将是电影名称(日期)/姓氏、名字/姓氏2、名字2/等等。我的代码包含一个类 Movie,它将电影名称转换为字符串。我如何能够在任何给定点搜索任何电影并让它拉出所有主演的演员?
public void loadDataFromFile(String fileName){
/**
* This method takes in one parameter, a file name, and prints out the data from that file
*/
Scanner theScanner3 = null;
myMovies = new ArrayList<Movie>();
try{
theScanner3 = new Scanner(new FileInputStream(fileName));}
catch(Exception ex){
System.err.println("IndexOutOfBoundsException: " + ex.getMessage());
}
while( theScanner3.hasNextLine()){
int i = 1;
i = i+1;
Movie foo = new Movie(theScanner3.nextLine());
myMovies.add(foo);
}
theScanner3.close();
}
我需要能够搜索电影的名称,并将它返回给我,该名称与该电影在同一行的每个演员。但是,我不知道该怎么做。
【问题讨论】: