- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert Properties list into a Map
To convert Properties list into a map, let us first create an object of Properties class −
=Properties p = new Properties();
Now, use setProperty() to set key-value pair −
p.setProperty("P", "1"); p.setProperty("Q", "2"); p.setProperty("R", "3"); p.setProperty("S", "4"); p.setProperty("T", "5"); p.setProperty("U", "6");
With that, the following is how the Properties list is converted into a Map −
HashMap<String, String>map = new HashMap<String, String>((Map) p);
Example
import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.Set; public class Demo { public static void main(String args[]) { Properties p = new Properties(); p.setProperty("P", "1"); p.setProperty("Q", "2"); p.setProperty("R", "3"); p.setProperty("S", "4"); p.setProperty("T", "5"); p.setProperty("U", "6"); p.setProperty("V", "7"); HashMap<String, String>map = new HashMap<String, String>((Map) p); Set<Map.Entry<String, String>>set = map.entrySet(); System.out.println("Key and Value of the Map... "); for (Map.Entry<String, String>m: set) { System.out.print(m.getKey() + ": "); System.out.println(m.getValue()); } } }
Output
Key and Value of the Map... P: 1 Q: 2 R: 3 S: 4 T: 5 U: 6 V: 7
- Related Articles
- Java program to convert the contents of a Map to list
- Haskell Program to Convert List to a Map
- Golang Program to Convert List to Map
- Java Program to convert a Map to a read only map
- Java program to convert a list of characters into a string
- Program to convert a Map to a Stream in Java
- Java Program to convert integer to String with Map
- Convert a Set into a List in Java
- Java Program to convert a list to a read-only list
- How to convert a List to a Map in Kotlin?
- Python program to convert a list of tuples into Dictionary
- Java Program to convert a List to a Set
- C# program to convert a list of characters into a string
- Java Program to Map String list to lowercase and sort
- How to convert a list collection into a dictionary in Java?

Advertisements