You must first use the CSV parsing library to parse comma separated values. Correct Analysis of CSV data is not as trivial as it seems at first glance. There are many good arguments not to reinvent this wheel.
It will also validate your code in the future and be a code that you do not need to test or maintain.
I know that the temptation to do something like data.split(','); strong, but this is a fragile and fragile decision. For one example, what if any of the values contains ".".
The second thing you need to do is parse the pairs. And again, the temptation to use String.split("="); will be strong, but it can be brittle and brittle if the right side = has = in it.
I am not a blind supporter of regular expressions, but I use them with restraint, they can only be the right tool for the job. Here is a regular expression for parsing name value pairs.
Regular expression ^ (. *) \ S? = \ s? ("? ([^"] *) "? |" (. *) ") $ , click on the regular expression to test it interactively. This works even for the multiple double quotes on the right side of the name value pair.
This will only correspond to what is to the left of the first = and everything else on the right side, and separate the optional " from the string values, while maintaining the numbers that coincide with the non-cyclic values.
List<String> list of encoded name value pairs specified.
final Pattern p = Pattern.compile("^(.*)\s?=\s?("?([^"]*)"?|"(.*)")$"); final Map<String, String> map = new HashMap<String, String>(list.size()); for (final String nvp : list) { final Matcher m = p.matcher(nvp); m.matches(); final String name = m.group(1); final String value = m.group(2); System.out.format("name = %s | value = %s\n", name, value); }