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?
CodePudding user response:
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))) {...