I want to split the below string and store it in a HashMap:
String currentString= "firstName-lastName-rollNum-departmentNum=firstName1-lastName1-rollNum1-departmentNum1";
I want my output to be store in map, like first string before hyphen (-)(firstName) and first string after (=)(firstName1),......... i.e.,
{firstName=firstName1,lastName=lastName1,rollNum=rollNum1,departmentNum=departmentNum1}
Below code doesn't work for my pattern:
Map<String,String> mapVal= null;
mapVal = Pattern.compile("\\s*=\\s*")
.splitAsStream(currentString.trim())
.map(s -> s.split("-", 2))
.collect(Collectors.toMap(a -> a[0], a -> a.length>1? a[1]: ""));
Once I split the string I don't understand how I can get my required values together as shown above. I apologize if you don't get my question.
Thanks in advance !!