Android开发中List的remove()方法
List集合有的remove()方法有两个:
1.remove(int
location),这个方法是根据下标从集合中移除相应的对象。
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);这个不可行
具体什么原因还是没有搞懂,希望大神指点
本文探讨了Android开发中List集合remove()方法使用的注意事项。通过具体示例说明了如何正确地从List中移除元素,特别是当使用remove(Object object)方法遇到问题时的解决策略。
217

被折叠的 条评论
为什么被折叠?



