Android lambda不包含无法正常工作

发布于 2025-02-08 09:32:37 字数 1105 浏览 1 评论 0原文

不知道为什么我不会从以下Android代码中获得的结果:

我想仅当PcKname 不包含 才能进入if字符串列表中的列出值。

List<String> listOfNonApps = Arrays.asList(".google.", "com.android.", "lenovo", ".bing.",".amazon.",".microsoft.",".projectpapyrus.","com.lenovotab");

if(!listOfNonApps.contains(pckName)){
      System.out.println("Nott Found");

我什至尝试了lambda:

if (!listOfNonApps.stream().noneMatch(el -> el.toLowerCase().contains(pckName)) {...  
if (listOfNonApps.stream().noneMatch(el -> el.toLowerCase().contains(pckName)) {...  
if (listOfNonApps.stream().noneMatch(el -> !el.toLowerCase().contains(pckName)) {...  
if (!listOfNonApps.stream().anyMatch(str -> str.contains(pckName))) {...
if (listOfNonApps.stream().anyMatch(str -> !str.contains(pckName))) {...

pckname 的格式:

com.google.android.apps.photos
com.google.android.deskclock
com.lenovotab.camera
com.dolby.daxappui2
com.android.settings
etc....

我认为这应该很简单,但它不起作用。它要么进入IF,并列出所有内容,无论如何还是跳过所有内容,因此永远不会进入IF语句。我是否正确使用了此?

Not sure why I am not getting the results I am looking for from the following Android code:

I am wanting to go into the IF only when the pckName does not contain one of the listed values in the list of strings.

List<String> listOfNonApps = Arrays.asList(".google.", "com.android.", "lenovo", ".bing.",".amazon.",".microsoft.",".projectpapyrus.","com.lenovotab");

if(!listOfNonApps.contains(pckName)){
      System.out.println("Nott Found");

I even tried Lambda:

if (!listOfNonApps.stream().noneMatch(el -> el.toLowerCase().contains(pckName)) {...  
if (listOfNonApps.stream().noneMatch(el -> el.toLowerCase().contains(pckName)) {...  
if (listOfNonApps.stream().noneMatch(el -> !el.toLowerCase().contains(pckName)) {...  
if (!listOfNonApps.stream().anyMatch(str -> str.contains(pckName))) {...
if (listOfNonApps.stream().anyMatch(str -> !str.contains(pckName))) {...

pckName is in the formats like:

com.google.android.apps.photos
com.google.android.deskclock
com.lenovotab.camera
com.dolby.daxappui2
com.android.settings
etc....

I would think this should be simple but its not working. It either goes into the IF and lists everything regardless or skips everything and never goes into the IF statement. Am I using this correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开柳相依 2025-02-15 09:32:37

看来您需要检查是否pckname包含任何子字符串,反之亦然。

if (listOfNonApps.stream().noneMatch(str -> pckName.contains(str))) {...

It looks like you need to check if you pckName contains any of substring, not vice versa.

if (listOfNonApps.stream().noneMatch(str -> pckName.contains(str))) {...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文