Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Iam not able to use jshell to create any interface i.e Map,Set or List, please help

Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m
Feb 16, 2018 11:18:20 AM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
| Welcome to JShell -- Version 9
| For an introduction type: /help intro

jshell> Map<String,String> veg = new HashMap<String,String>();
| Error:
| cannot find symbol
| symbol: class Map
| Map<String,String> veg = new HashMap<String,String>();
| ^-^
| Error:
| cannot find symbol
| symbol: class HashMap
| Map<String,String> veg = new HashMap<String,String>();
| ^-----^

2 Answers

Yanuar Prakoso
Yanuar Prakoso
15,196 Points

Hi there...

You need to import Map and HashMap first from java.util

Here is how you should do it:

jshell> import java.util.Map;

jshell> import java.util.HashMap;

jshell> Map<String, String> veg = new HashMap<>();

veg ==> {}

jshell>

I hope this can help

thanks allot