In a list of strings, the individual strings have a bunch of numbers separated by commas.
ex.
List<String> numberGroups = {"55,46,10,0,85,80,67","100,64,70,6","1,23,59,60","5,0,98,54"};
I want to identify numberGroups that only have a single "0".. but my code is finding any "0" and returning all the groups since the others contain a 0 in "100", "70".. etc. I only want to find strings with a single 0 and add that string to a list to return.
Here is what I have -
public static List<String> findGroups(List<String> groups){
List<String> grp = new ArrayList<>();
for(String x : groups) {
if(x.contains("0")) {
grp.add(x);
}
}
return grp;
}
``
question from:
https://stackoverflow.com/questions/65877523/how-do-i-find-a-specific-string-in-a-list-of-strings-with-similar-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…