String line = "language=java"; // example input String []pair = line.split("="); if (pair.length != 0) { String var = pair[0]; String val = pair.length > 1 ? pair[1] : ""; System.out.println(var + " equals + val); }This works for cookies, .ini files, etc Regular expressions are another way. This does *not* deal with an equals in the value.
Programming Tips - Java: Best way to parse a variable=value pair
Date: 2012apr16
Language: Java
Q. Java: Best way to parse a variable=value pair
A. Use split() like this: