0

I have a string as below which needs to be converted to HashMap.

String datasample="{SessionID=ACVRT5678897DERT, Name=ACFGTYR, Age=34, sessionTime=20210428}"

I tried using Java 8 lambda ,stream and collect and it works when datasample does not include "{" and "}". But My string includes "{" and "}".

Please suggest.

Eritrean
  • 13,003
  • 2
  • 20
  • 25
user15345826
  • 29
  • 1
  • 4

1 Answers1

1

If you have code that works when the characters "{" and "}" aren't present then couldn't you just remove these?

String dataSample="{SessionID=ACVRT5678897DERT, Name=ACFGTYR, Age=34, sessionTime=20210428}"
sampleToUse = dataSample.substring(1, dataSample.length() - 1);   //Remove 1st and last char
//run sampleToUse through your lambda
tomgeraghty3
  • 1,134
  • 5
  • 9