-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