Android开发中List的remove()方法

来源:互联网 发布:织梦cms好用吗 编辑:程序博客网 时间:2024/06/01 07:21

Android开发中List的remove()方法

  List集合有的remove()方法有两个:
                     1.remove(intlocation),这个方法是根据下标从集合中移除相应的对象。
    2.remove(Object object),这个方法是根据对象从集合中移除第一次出现的这个对象。
  但是在Android的一次实际开发中,调用第二个方法根据一个对象一直无法删除相应的对象,所以只能使用遍历集合然后根据第一种方法去删除这个对象。
public void onMemberLeft(String s, IM800MultiUserChatRoomParticipant im800MultiUserChatRoomParticipant) {    for (int i = 0; i <mIM800UserProfiles.size(); i++) {        if (mIM800UserProfiles.get(i).getJID().equals(im800MultiUserChatRoomParticipant.getJID())){            mIM800UserProfiles.remove(i);        }    }}
  mIM800UserProfiles.remove(im800MultiUserChatRoomParticipant);这个不可行
  具体什么原因还是没有搞懂,希望大神指点
                       
1 0
原创粉丝点击