String a = "r";
String b = "l";
for (String s : list) {
boolean r = s.indexOf(a) >= 0;
boolean l = s.indexOf(b) >= 0;
//返回指定字符在此字符串中第一次出现处的索引。
if (r && !l) continue;
if (!r && l) result.add(s);
result.add(s);
}
boolean l = s.indexOf(b) >= 0; 这里的 >= 0 是不是因为 数组的下标不能小于0?
if (r && !l) continue;
if (!r && l) result.add(s);
这里面的条件 为什么要取反呀 ??
求大佬 救救迷茫的我吧
已解决
评论 (2)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Gellert Varga
14 二月 2022, 10:26解决方法
See for yourself what results you get in the following cases:
"summer".indexOf("s") // = 0
"windows".indexOf("s") // = 6
"no".indexOf("s") // = -1
So if you get a result less than zero, it means that the given character does not occur in that string.
boolean s = "no".indexOf("s") >= 0; // s = false!
+2
Gellert Varga
14 二月 2022, 10:32解决方法
+2