
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How can we implement a map in JShell in Java 9?
JShell is a java shell tool that has introduced in Java 9. It is an interactive tool that reads input, executes it, and prints it in the command-line prompt. We don't need to write a main() method to execute it like Java class.
We can implement different collections includes set, list, and map in the JShell tool. The important collection is the Map interface, and it is a key-value pair. A Map doesn't contain duplicate keys and each key maps to at most one value.
In the below example, we can able to implement the non-empty map.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> Map<String, String> map = new HashMap<String, String>(); map ==> {} jshell> map.put("raja", "ramesh"); $2 ==> null jshell> map.put("adithya", "sai"); $3 ==> null jshell> map.put("jai", "dev"); $4 ==> null jshell> map.put("chaintaya", "krishna"); $5 ==> null jshell> Map<String, String> immutableMap = Collections.unmodifiableMap(map); immutableMap ==> {raja=ramesh, jai=dev, chaintaya=krishna, adithya=sai} jshell>
- Related Articles
- How to implement a String in JShell in Java 9?
- How can we avoid compilation errors in JShell in Java 9?
- How can we load a source code into JShell in Java 9?
- How can we import a gson library in JShell in Java 9?\n
- How can we customize the start of JShell in Java 9?
- How to implement a lambda expression in JShell in Java 9?
- How to implement a Set interface in JShell in Java 9?
- How to implement java.time.LocalDate using JShell in Java 9?
- How can we execute snippets by ID in JShell in Java 9?
- How to implement an ArrayList using JShell in Java 9?
- How to implement JShell using JavaFX in Java 9?\n
- How to implement the encapsulation concept in JShell in Java 9?
- How to implement the Fibonacci series in JShell in Java 9?
- How to implement integer type conversion in JShell in Java 9?
- How can we create an unmodifiable Map in Java 9?\n

Advertisements