找到数组的非相交元素的最佳方法
我有2个用户对象。 1个数组包含所有用户的列表 第二个数组包含所有已记录用户的列表。 这是在用户中找到未遇到的最佳方法
I have 2 arrays of User Objects.
1 array contains list of all users
and 2nd array contains list of all logged in Users.
Which is the best way to find non-logged in users
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种情况:
最简单的方法是获取所有用户识别符,例如databaseID或用户名。将其持续到哈希结构中,以进行快速搜索。然后浏览所有用户,接受本集合中未包含的所有用户。
创建一组已记录的用户标识符:
现在您可以找到所有未燃烧的用户:
如果您实现了平等和哈希代码,则可以简单地将所有记录的用户从所有用户集合的副本中删除。只需记住先创建一个副本,否则您只会以记录和未登录的用户结束。
现在,您将拥有一个只有未记录的用户的集合。
There are two cases:
then the simplest way would be to get all UserIdentifier, like databaseId or username. Persist it in a hashed structure, for fast search. Then go through all Users and accept all not contained in this collection.
Create a set of logged user Identifiers:
Now you can find all not-logged users:
If you have equals and hash code implemented, then you could simply remove all logged users from a copy of all Users collection. Just remember to create a copy first, otherwise You will end with only logged and not-logged Users.
Now you will have a collection with only not logged users.