Java tutorial
//package com.java2s; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Main { /** * Parses and returns CGI arguments. * * @param rest the string to parse * @return CGI arguments from <tt>rest</tt> */ public static Map<String, String> parseArgs(final String rest) { if (isEmpty(rest)) return Collections.emptyMap(); final Map<String, String> res = new HashMap<String, String>(3); for (StringTokenizer st = new StringTokenizer(rest, "&", false); st.hasMoreTokens();) { final String pair = st.nextToken(); final int ieq = pair.indexOf('='); String key, val; if (ieq == -1) { key = pair; val = null; } else { key = pair.substring(0, ieq); val = pair.substring(ieq + 1); } res.put(key.trim(), val == null ? val : val.trim()); } return res; } /** * Returns <code>true</code> if <code>s</code> is <code>null</code> or * <code>""</code>, otherwise <code>false</code>. * * @param s {@link String} in question * @return <code>true</code> if <code>s</code> is <code>null</code> or * <code>""</code>, otherwise <code>false</code>. */ public static boolean isEmpty(final String s) { return s == null || s.equals(""); } }