I am getting an error message.
Suspicious call to java.util.Map.ContainsValue Given object cannot contain instance of String (Except ArrayList)
This is a small version of the program that I am working with. Could someone suggest how to fix this? Please post code. I am not a strong programer.
import java.util.ArrayList;
import java.util.HashMap;
public class Main {
public static void main(String[] a) {
HashMap<String,ArrayList> map = new HashMap<String,ArrayList>();
//hashMap.put(key, new ArrayList());
map.put("key1", new ArrayList());
map.get("key1").add("value2");
//System.out.println(map.containsKey("key1"));
System.out.println(map.containsValue("value2"));
}
}
You have an HashMap that has Strings for keys and ArrayLists for values:
HashMap<String,ArrayList> map = new HashMap<String,ArrayList>();
You then try and see if it contains a value which is a String
System.out.println(map.containsValue("value2"));
That's very suspicious. Because it can't ever have that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With