Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error on token(s), misplaced construct(s)

Tags:

java

hashmap

I've the code:

Map<String, String> map = new HashMap<String, String>;

Now in Eclipse is new HashMap<String, String> red underlined.

The Error: Syntax error on token(s), misplaced construct(s)

What does it mean and how can i fix it?


2 Answers

It should be

Map<String, String> map = new HashMap<String, String>(); //<-- add parentheses
like image 64
Esailija Avatar answered Dec 02 '25 09:12

Esailija


Just add a ()! Map<String, String> map = new HashMap<String, String>();

With new HashMap, you call the HashMap.java. To initialize the HashMap, you should call the Constructer. Here with ().

like image 24
Michael Schmidt Avatar answered Dec 02 '25 10:12

Michael Schmidt