Android lambda不包含无法正常工作
不知道为什么我不会从以下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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您需要检查是否
pckname
包含任何子字符串,反之亦然。It looks like you need to check if you
pckName
contains any of substring, not vice versa.