System.out.println("Enter the appointment ID to see the full details :");
int y=in.nextInt();
int r;
for(r=0;r<count;r++)
{
if(all.get(r).getID()==y)
{
all.get(r).display();
}
}
我正在使用这段代码通过get语句检索已输入的完整详细信息并进行显示。这是我的程序的一小部分。我想知道是否有其他方法来实现它。
containsKey
再调用get
是不良实践。 - Boris the Spiderget()
调用来替换它,但在这样一个简单的程序中,我不认为优化有什么意义。无论如何,OP都不能使用 HashMap,所以这并不重要。 - Eran