1

I have java String like below

String mStr = "Key1:value1   key2:value2   key3:value3"

How to convert/add this string in to java Hash map..?

1 Answer 1

2

Just use this regex with 2 captured groups:

(\w+):(\w+)

In Java:

Pattern p = Pattern.compile("(\\w+):(\\w+)");

Then iterate the results using while (matcher.find()) and grab both captured groups.

RegEx Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.