Thanks rob, i change the code and store the entire LinkedList. It works and node can be retrieved well also. But I have another problem. My assignment is desige a AddressList class(main class) which compose of AddressCard (the linked nodes). AddressCard is stored in LinkList. The LinkList has an inner class--LinkListIterator which implements Iterator(interface). I can not used jave predesigned LinkedList.
The requirement ask input a
String(Title of AddressCard) and find a AddressCard object which has same title.
The find() I write as belows,
//------------------------find first address--------------------------
public void find()
{
Scanner kb2 = new Scanner(System.in);
System.out.print("please input first name:");
String str=kb2.nextLine();
boolean FIND=false;
AddressCard a=null;
while(lnklst.iterator().hasNext())
{
if(lnklst.iterator().next().getname().startsWith(str))
{
FIND=true;
a=lnklst.iterator().next();
break;
}
}
if(!FIND) System.out.println("NOT FIND");
else System.out.println("You have find the
address:\n"+a);
Compile is ok, but when I run, while(lnklst.iterator().hasNext()) became a deadlock. I am confused why the iterator cann't work. Can you give me a hint. Thanks
[ May 15, 2008: Message edited by: max wang ]