11. HashMap: Access


#1

I have a headache already trying to figure out what's wrong with the code. I would really appreciate it SO MUCH if anyone could tell me what's going on, why am I getting an error when I try this code.

import java.util.HashMap;

public class Restaurant {
public static void main(String[] args) {

HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();

restaurantMenu.put("Turkey Burger", 13);
restaurantMenu.put("Naan Pizza", 11);
restaurantMenu.put("Cranberry Kale Salad", 10);

  System.out.println(restaurantMenu.get ("Naan Pizza"));

}

}


#2

@geogolden,
Have you tried using

 System.out.println(restaurantMenu.get("Naan Pizza"));

without a space between the get and the opening-parenthesis-(


#3

Wow what?! I thought spaces didn't matter "AT ALL" in this program.. Why did that space make such a big difference?
p.s. Thanx a lot, but in reality I would appreciate even more if you could explain to me why was that space such a big deal


#4

Because basically when you say .get() , your calling a function Java made for you.... Its a Hash-Map built in function, so when you use a function you know there must be no spaces like this

function funcName(){

}
//Calling
funcName();

So thats why...