code: public static List<String> getList(final String val, final boolean emptyOk) throws Throwable {
      List<String> l = new LinkedList<String>();
  
      if ((val == null) || (val.length() == 0)) {
        return l;
      }
  
      StringTokenizer st = new StringTokenizer(val, ",", false);
      while (st.hasMoreTokens()) {
        String token = st.nextToken().trim();
  
        if ((token == null) || (token.length() == 0)) {
          if (!emptyOk) {
            // No empty strings
  
            throw new Exception("List has an empty element.");
          }
          l.add("");
        } else {
          // Got non-empty element
          l.add(token);
        }
      }
  
      return l;
    }
docs: Turn a comma separated list into a List.
  Throws exception for invalid list.
  
  @param val     String comma separated list
  @param emptyOk Empty elements are OK
  @return List of elements, never null
  @throws Throwable for invalid list