In C#
Dictionary<String, String> dictionary = new Dictionary<String, String>();
In Java, this errors with
Cannot instantiate the type
Dictionary
What could be wrong?
In my code this follows with
dictionary.put("vZip", jsonUdeals.getString("vZip"));
I know this sounds too trivial. But I am at a loss!
If Dictionary doesn’t do it(which I strongly suspect by now), then which DataStructure to use.
Dictionaryis an abstract class in Java. It is also obsolete; you should use theMapinterface instead; something like:Note that
HashMap<K,V>is a concrete class, but we’re assigning it to aMap<K,V>reference, which is an interface. This is the recommended style in Java, because it allows you to switchHashMapfor e.g.Hashtableat a later stage, without having to change everything.