Buffered Reader: read and save certain parts of a line with HashMap (in java?)

qwertyuiopqwertyuiop :

I have a text file that has these two lines:

PC Looks like the killer was panicking and searched for help as soon as he could......
Cupboard I understand this is quite the scene to stomach for your first mystery

Using BufferedReader, I would like to save the first word (PC for example) as a HashMap key and the following sentence as its value.

I have searched online for the answer to this and I found a question, created by Rumen, that was answered very similarly to what I was looking for. However, they used line.split() which would only work if I had something like:

PC On

as that would save PC as the key and On as the value. Secondly, user funglejunk, another answer used ProcessInformation (as a parameter for list) and I have not learnt about that yet (but will put it on the list!.)

Here is the answer I am reffering to.

Appreciate all help!

Muhammad Qasim :
String key = line.substring(0, line.indexOf(' '));
String value = line.substring(line.indexOf(' ') + 1);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=300055&siteId=1