【发布时间】:2014-02-06 12:37:06
【问题描述】:
我有一个看起来像这样的对象:
Account account = new Account (0, fName, sName, adr, city, pos, uniqueID);
然后我通过用户输入将该对象放入 ArrayList:
List<Account> newAcc = new ArrayList<Account>();
这就是问题所在。我需要一种巧妙的方法来根据用户输入删除该对象。这是我尝试过的:
System.out.print("1. Client with Accounts.\n2. Client with Savings Accounts.\n3. Remove all Accounts.\n");
int inputRmv = in.nextInt();
case 1:
for (Iterator i = newAcc.iterator(); i.hasNext(); ) {
if (i.equals(rmvID)) {
newAcc.remove(i);
这不起作用。对象不会以这种方式被移除。
基本上:有没有办法使用用户输入,然后遍历列表以查看是否有任何对象包含与该对象的任何部分等效的字符串?
我急需,因此非常感谢任何帮助我朝正确方向前进的帮助!
干杯。
【问题讨论】:
-
在第一篇文章中引用了错误的数组,对不起。
标签: java object arraylist iterator