how to remove a object from linked list in java?

后端 未结 7 900
花落未央
花落未央 2020-12-15 14:08

i have one problem with my code ,i did a sample program to display the emp details from a linked list,now the problem when i trying to delete a particular entry means it doe

7条回答
  •  佛祖请我去吃肉
    2020-12-15 14:54

    The code tries to remove element at index position 101, but there are only four items in the list.

    Use the following as a replacement of your code:

    for( EmpDedup data : list)
    {
       if( data.getRecord() == rec1 )
       {
            list.remove( data );     
             ++count;
        }
    }
    

    That's where a list object will be deleted.

提交回复
热议问题