-2
boolean run = true;
while(true)
{
System.out.println("Enter A to add, S to search, E to exit");
String temp = input.next();
switch(temp)
{
case "A":
case "a":
System.out.println("Please enter the building name: ");
newClassroom.setBuildingName(input.next());
System.out.println("Please enter the room number: ");
newClassroom.setRoomNumber(input.next());
System.out.println("Please enter the capacity: ");
newClassroom.setCapacity(input.nextInt());
System.out.println("Please enter the academic department: ");
newClassroom.setAcadDept(input.next());
System.out.println("Please enter whether or not the room has a projector: ");
newClassroom.setProjector(input.nextBoolean());
List.add(newClassroom);
break;
case "S":
case "s":
System.out.println("Enter the building name and room number you wish to locate");
//String buildingSearch = input.next();
//int roomSearch = input.nextInt();
System.out.println(List);
//System.out.println(buildingSearch + roomSearch);
Classroom temporary = new Classroom();
temporary.setBuildingName(input.next());
temporary.setRoomNumber(input.next());
break;
case "E":
case "e":
System.exit(0);
}
}
}
我想檢查一下,看看ArrayList中是否包含一個對象。我試過使用包含,但有人說我應該嘗試使用.equals()來代替。檢查輸入的對象是否包含在一個數組列表中
包括()應該工作的罰款。你有關於contains()的任何問題嗎? – yogidilip
有人錯了,Contains將迭代列表並使用.equals()方法檢查每個值。您無需爲Strings提供自己的實現。 – Reinard