根据ID比较两个不同的列表
我在这里要做的是,我正在尝试通过CustomerFavoriteRepository的ID找到文章。我有两个不同的列表(Arclelist,Favlist),并且正在比较列表的ID并将其添加到空数组(Favartlist)中。有人帮助我如何实现循环? 我在循环中的“ favartlist.add()”点上遇到错误,我不知道我必须在那里给出哪个值。谢谢
what I am trying to do here is I am trying to find articles by given id from the CustomerFavoriteRepository. I have two different lists (articleList,FavList ) and I am comparing the ids of both lists and adding them to the empty array (FavartList). Does anyone help me with how can I achieve that using for loop?
I am getting errors at the point of "FavartList.add()" in the loop i don't know which value I have to give there. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您问题的简单答案是您需要构造
newCustomerFav
,然后将其传递到add
方法:在其他注意事项上,您的算法可以在此处进行改进 - 右现在,它将按照n * m操作的顺序来构建
customfavartlist
,其中n是文章的数量,m是收藏夹的数量。可以减少它,以便算法在N + M的顺序上执行,而在有很多文章时,该算法的扩展会更好,并且客户有许多收藏夹。
这样做的方法是从FairitesList创建ID的
set
,类似的是:The simple answer to your question is that you need to construct the
NewCustomerFav
, and pass it to theadd
method:On a different note, your algorithm can be improved here - Right now it will take on the order of n * m operations to build
customFavartList
, where n is the number of articles, and m is the number of favorites.It can be reduced so that the algorithm performs on the order of n + m, instead, which will scale much better when there are many articles, and the customer has many favorites.
The way to do it is to create a
Set
of ids from the favoritesList, something like this: