Java Program to read map by Map.Entry

Java 8Object Oriented ProgrammingProgramming

To read the Map, first use getProperties() ad then iterator to iterate through the entire list of Map −

Properties prop = System.getProperties();
Iterator i = prop.entrySet().iterator();

Now, loop through Map.Entry and get the key-value pair for the Map −

while (i.hasNext()) {
   Map.Entry entry = (Map.Entry) i.next();
   System.out.println(entry.getKey() + " => " + entry.getValue());
}

Example

 Live Demo

import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
public class Demo {
   public static void main(String[] a) {
      Properties prop = System.getProperties();
      Iterator i = prop.entrySet().iterator();
      while (i.hasNext()) {
         Map.Entry entry = (Map.Entry) i.next();
         System.out.println(entry.getKey() + " => " + entry.getValue());
      }
   }
}

Output

sun.desktop => windows
awt.toolkit => sun.awt.windows.WToolkit
java.specification.version => 11
sun.cpu.isalist => amd64
sun.jnu.encoding => Cp1252
java.class.path =>
java.vm.vendor => Oracle Corporation
sun.arch.data.model => 64
user.variant =>
java.vendor.url => http://java.oracle.com/
user.timezone =>
os.name => Windows 10
java.vm.specification.version => 11
sun.java.launcher => SUN_STANDARD
user.country => US
sun.boot.library.path => C:\Program Files\Java\jdk-11.0.2\bin
sun.java.command => Amit/my.Demo
jdk.debug => release
sun.cpu.endian => little
user.home => C:\Users\amit_
user.language => en
java.specification.vendor => Oracle Corporation
jdk.module.path => C:\Users\amit_\eclipse-workspace3\Amit\bin;C:\Users\amit_\Downloads\javatuples-1.2.jar\javatuples-1.2.jar
java.version.date => 2019-01-15
java.home => C:\Program Files\Java\jdk-11.0.2
file.separator => \
java.vm.compressedOopsMode => Zero based
line.separator =>
java.specification.name => Java Platform API Specification
java.vm.specification.vendor => Oracle Corporation
java.awt.graphicsenv => sun.awt.Win32GraphicsEnvironment
jdk.module.main.class => my.Demo
jdk.module.main => Amit
user.script =>
sun.management.compiler => HotSpot 64-Bit Tiered Compilers
java.runtime.version => 11.0.2+9-LTS
user.name => amit_
path.separator => ;
os.version => 10.0
java.runtime.name => Java(TM) SE Runtime Environment
file.encoding => Cp1252
java.vm.name => Java HotSpot(TM) 64-Bit Server VM
java.vendor.version => 18.9
java.vendor.url.bug => http://bugreport.java.com/bugreport/
java.io.tmpdir => C:\Users\amit_\AppData\Local\Temp\
java.version => 11.0.2
user.dir => C:\Users\amit_\eclipse-workspace3\Amit
os.arch => amd64
java.vm.specification.name => Java Virtual Machine Specification
java.awt.printerjob => sun.awt.windows.WPrinterJob
sun.os.patch.level =>
java.library.path => C:\Program Files\Java\jdk-11.0.2\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jdk-11.0.2/bin/server;C:/Program Files/Java/jdk-11.0.2/bin;C:\Program Files (x86)\ImageMagick-7.0.8-Q16;C:\Program Files\ImageMagick-7.0.8-Q16;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Java\jdk-11.0.2\bin;C:\xampp\apache\bin;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Users\amit_\AppData\Local\Microsoft\WindowsApps;;C:\WINDOWS\system32;;.
java.vendor => Oracle Corporation
java.vm.info => mixed mode
java.vm.version => 11.0.2+9-LTS
sun.io.unicode.encoding => UnicodeLittle
java.class.version => 55.0
raja
Published on 25-Apr-2019 09:09:18
Advertisements