我正在尝试通过我的输入(扫描仪)从我的 ArrayList(memberList) 中删除 MemberPlayer(object)
我试过环顾谷歌和堆栈,但似乎找不到任何使用扫描仪的东西。
public void removeMember(){
System.out.println("Which MemberPlayer are you looking for?:");
System.out.print("Input first name: ");
String fName = input.nextLine().toUpperCase();
System.out.print("Input last name: ");
String lName = input.nextLine().toUpperCase();
for (MemberPlayer m: memberlist){
if(m.getFirstName().contains(fName) && m.getLastName().contains(lName)) {
System.out.println();
System.out.println("This MemberPlayer exist:");
System.out.println(fName + " " + lName);
System.out.print("Do you want to remove this MemberPlayer? [yes/no]");
input.nextLine().toUpperCase();
if (input.equals("Yes")) {
memberlist.remove(); //I can't figure out how to write this line?
}else{
break;
}
}else {
System.out.println();
System.out.println("This MemberPlayer doesn't exist");
System.out.println();
break;
}
}
}
我从 file.txt 中读取了我的成员列表,其中包含以下信息:名字、姓氏、年龄和团队。
ANDERS
ANDERSEN 23 1
BERT BERSEN 16 2
HANS HANSEN 25 1
TIM TIMSEN 20 2
MORTEN MORTENSEN 34 1
杨魅力
慕标5832272
肥皂起泡泡
相关分类