gpt4 book ai didi

java - 我正在尝试从 JAVA 中的 MultiMap(org.apache.commons.collections.MultiMap) 中删除单个值

转载 作者:行者123 更新时间:2023-11-30 08:10:15 28 4
gpt4 key购买 nike

我正在尝试从 Java 中的 MultiMap (org.apache.commons.collections.MultiMap) 中删除单个值。问题是它包含两个值。当我删除一个时,另一个也会被删除。

class MappedValue
{
public MappedValue(String id , boolean touched) {
identifier = id;
this.touched=touched;
}

private String identifier;
private boolean touched;
}

MultiMap SuccessorsArray = new MultiValueMap();

MappedValue mv = new MappedValue("1", false);
MappedValue mv2 = new MappedValue("2", true);

SuccessorsArray.put("key1", mv );
SuccessorsArray.put("key1", mv2 );
//Below is the problem as both values in the get removed instead of 1(mv).
SuccessorsArray.remove("key1", mv);

最佳答案

我刚刚测试了 3.2.1 版本

public static void main(String[] args) {
class MappedValue {
public MappedValue(String id, boolean touched) {
identifier = id;
this.touched = touched;
}
private String identifier;
private boolean touched;
@Override
public String toString() {
return "MappedValue [identifier=" + identifier + ", touched=" + touched + "]";
}
}

MultiMap multiMap = new MultiValueMap();
MappedValue mv = new MappedValue("1", false);
MappedValue mv2 = new MappedValue("2", true);
multiMap.put("key1", mv);
multiMap.put("key1", mv2);
//Below is the problem as both values in the get removed instead of 1(mv).
multiMap.remove("key1", mv);
System.out.println(multiMap.get("key1"));
}

返回[MappedValue [identifier=2,touched=true]]

所以该值确实没有被删除。

关于java - 我正在尝试从 JAVA 中的 MultiMap(org.apache.commons.collections.MultiMap) 中删除单个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30485387/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com