I am having compiler issues with the syntax and want this method to work on the Hashmap object myMap. I need the Add method to take a String value and use the Hashmap put function to add a (key, value) pair.
I tried to put the factory method initiation of newMap inside main and had access issues.
import java.util.*;
public class MyMap {
public static String item;
public static String brand;
Map<String, String> myMap = newMap();
public static void main(String[] args) {
myMap.Add("apple");
}
public static HashMap<String, String> newMap() {
return new HashMap<>();
}
public static void Add(String item) {
String brand = "nobrand";
myMap.put(item, brand);
}
}
compilation error due to static/non static items. I made them all static to make everything accessible throughout the class.