所以,我有ArrayList中,我储存的动物。将ArrayList <String>打印成输出?
private ArrayList<Animal> catalog = new ArrayList<>();
现在,我需要打印目录到我的输出当我按下4到我的输出。
case 4:
System.out.println("List of animals: ");
printIt(); //Function to print catalog
break;
我试着用
private boolean InList(String name) {
for (int i = 0; i < catalog.size(); i++) {
if (name.equalsIgnoreCase(catalog.get(i).getName())) {
return true;
}
}
return false;
}
做,但它不工作。你们能帮我拿到这段代码吗?
更多信息,你为什么不只是尝试打印动物名录? –
请将'printIt',以及'InList'如何相关? –
当我尝试只打印“目录”中存储的动物,我会得到“[[email protected]]” 为printit在这里 私人字符串为printit(){ 字符串动物=名称; //catalog.add(); 归还动物; } –