public class array {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("fruit.txt"));
System.out.println("enter the fruit you want to search");
Scanner input = new Scanner(System.in);
String fruit = input.nextLine();
String line;
List<String> list = new ArrayList<String>();
while((line=reader.readLine()) !=null)
{
list.add(line);
}
reader.close();
for (String s : list) {
System.out.println(s);
}
}
}
我有水果.txt
apple 20 good
orange 30 good
banana 40 needmore
如何从数组列表中检索我有多少橙子。我希望程序在这种情况下读取用户输入“橙色”并显示 30 并且状态不好。
理想的输出是
You have orange 30 of them and status is good