这返回 false...我期待 true
List<String> listA // [941, 946, 940, 942]
List<String> listB //[941, 942, 940, 946,888, 466, 777]
listB.containsAll(listA) //FALSE ??
Run Code Online (Sandbox Code Playgroud)
false结果意味着 中的某些值在listA中没有对应(相等)的值listB。这可能是由一些不必要的空格引起的。你需要知道
"foo".equals(" foo")
Run Code Online (Sandbox Code Playgroud)
将返回false,这意味着使用的值不相等,因为空格也算作字符。
如果每个字符串的格式正确,您提供的示例数据就可以正常工作。
import java.util.Arrays;
import java.util.List;
public class Test {
public static final void main(String[] ignored) {
List<String> listA = Arrays.asList(new String[]{"941", "946", "940", "942"});
List<String> listB = Arrays.asList(new String[]{"941", "942", "940", "946", "888", "466", "777"});
System.out.println(listB.containsAll(listA));
}
}
Run Code Online (Sandbox Code Playgroud)
输出:true
| 归档时间: |
|
| 查看次数: |
4372 次 |
| 最近记录: |