• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading values from a String

 
siva sankar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am hitting a webservice which is returning a String as shown below.

String output="identitydetails.attribute.name=uid
identitydetails.attribute.value=John
identitydetails.attribute.name=mail
identitydetails.attribute.value=john@abc.com
identitydetails.attribute.name=sn
identitydetails.attribute.value=D";


In the above output,each line contains a attribute name and the next corresponding line have the value for this attribute.
For example,the line1 and line2 in above output is identitydetails.attribute.name=uid and identitydetails.attribute.value=John.
Now I want to add uid(from line1) as a key and John(from line2) as value to a HashMap. The same has to be done for other lines in the output and add key/value pairs to HashMap.


Can anyone suggest me the best approach to achieve the above requirement.

Thanks in Advance,
SivaReddy
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the name=value format used by "properties" so you could create a java.util.Properties object to hold and read values.

Create a StringReader from the String, create an empty Properties and then load it from the Reader.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic