This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Wondering what would be the best way to store a text string delimited by some sort of separator (e.g. ',') where the first element of the string would be the key and rest would be the value? For example I would like to have a text string like -
'0001, abc, cde, xyz, 11/30/05' stored in a hashMap where the key would be 0001 and the value would be - 'abc, cde, xyz, 11/30/05'.
Later I would be comparing other strings with matching values of the first element. I guess using HashMap would be an efficient way to do this comparison?
How about using the String.split method. You can use Regex to get the first comma as the split point, then you have two Strings in the returned String array, get the 0 element as the Key and the 1 element as the value.