JShell is an interactive command-line tool introduced in Java 9. It is also called a REPL tool that takes input, evaluates it, and prints output to the user.
In the JShell tool, it's possible to list all variables created by using the internal command "/vars". We have different "/vars" commands available in the JShell tool as listed below.
/vars /vars [ID] /vars [Variable_Name] /vars -start /vars -all
In the below code snippet, created expression and variable. Then we can able to apply different "/vars" commands.
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> 2 + 4 $1 ==> 6 jshell> /vars | int $1 = 6 jshell> int x = 20 x ==> 20 jshell> /vars | int $1 = 6 | int x = 20 jshell> /vars $1 | int $1 = 6 jshell> /vars x | int x = 20 jshell> /vars -all | int $1 = 6 | int x = 20 jshell> /drop x | dropped variable x jshell> /vars -all | int $1 = 6| int x = (not-active)