【问题标题】:LinkedHashSet: "contains" issueLinkedHashSet:“包含”问题
【发布时间】:2019-05-12 11:35:54
【问题描述】:

这段代码有什么问题?

Set<String> A = new LinkedHashSet<String>(); 
Set<String> B = new LinkedHashSet<String>();
Set<String> C = new LinkedHashSet<String>();

// A and C are filled before the piece of code below:

for (String ce: A){
   if (!C(ce))
     B.add(ce);
}

A 中有一些字符串不在 C 中。因此,我希望 B 有一些元素,但当我打印它时它总是空的。注意:ArrayList 也会发生这种情况。

谢谢。

【问题讨论】:

  • 我不熟悉 if (!C(ce)) 的语法。这应该是做什么的?

标签: contains linkedhashset


【解决方案1】:

正确说明:

if(!C.contains(ce))

我想检查 A 中的字符串是否不在 LinkedHashSet C 中。所有不在 C 中的字符串都应添加到 B。谢谢。

【讨论】:

    猜你喜欢
    • 2013-11-07
    • 1970-01-01
    • 2011-02-09
    • 2010-09-08
    • 1970-01-01
    • 2014-10-09
    • 2011-06-27
    相关资源
    最近更新 更多