Good day. I try to learn associative arrays. Available: UPD
import java.util.*; class Map { int a; String value; String key; HashMap<String, String> map; Map(){ HashMap<String, String> map = new HashMap<String, String>(); map.put("key1", "value1"); map.put("key2", "value2"); map.put("key3", "value3"); } int getSize(){ return map.size(); } String getValue(String key) { this.key = key; return map.get(key); } } public class Pr10_2 { public static void main(String[] args) { Map mp = new Map(); System.out.println(mp.getSize()); System.out.println(mp.getValue("key1")); } }
I'm trying to get the value of key1
value
getValue
method, but the editor emphasizes the map in the line return map.get(key);
. It was the same with getSize()
, I had to do it differently. Can you please tell me, can I somehow incorrectly request the value? Or announce something wrong?