How to convert a String into a Map in Java

Hey there!

Welcome to

In this post, we will look at the program to convert a String into a Map in Java.

Consider if a String is having KeyValuePairs delimited by another character, we can split the string and load them into a Map instance.


                 input = “1=ONE,2=TWO,3=THREE,4=FOUR”

we would like to load it into a Map instance as below

                {{1 -> “ONE”}, {2 -> “TWO”}, {3 -> “THREE”}, {4 -> “FOUR”}}


Let’s look at the program:


Please let me know in case of any queries.

Happy Learning :).

Leave a Reply

Your email address will not be published. Required fields are marked *