Java Utililty Methods Args Parse

List of utility methods to do Args Parse

Description

The list of methods to do Args Parse are organized into topic(s).

Method

MapparseArgs(String[] args)
parse Args
Map paramMap = new HashMap();
if (args != null) {
    int count = 1;
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg != null) {
            if (arg.startsWith("-")) {
                paramMap.put(arg, "");
...
HashMapparseArguments(final String[] args)
Parse commandline arguments
final HashMap<String, Object> arguments = new HashMap<String, Object>();
for (String s : args) {
    if (s.startsWith("--")) {
        s = s.substring(2);
    } else if (s.startsWith("-")) {
        s = s.substring(1);
    final int eqIdx = s.indexOf('=');
...
MapparseArguments(String[] args)
parse Arguments
Map<String, String> arguments = new HashMap<>();
for (String arg : args) {
    int pos = arg.indexOf('=');
    if (pos <= 0) {
        throw new IllegalArgumentException("Bad argument " + arg);
    String key = arg.substring(0, pos);
    String value = arg.substring(pos + 1);
...
HashMapparseCLInput(String[] args)
parse CL Input
HashMap<String, String> map = new HashMap<String, String>();
for (int i = 0; i < args.length; i++) {
    if (args[i].indexOf("-") == 0) {
        if (i + 1 < args.length) {
            final String key = args[i].substring(1);
            final String value = args[i + 1];
            System.out.println(key + "=" + value);
            map.put(key, value);
...
HashMapparseCommandLine(String[] args)
parse Command Line
HashMap<String, String> configParameters = new HashMap<String, String>();
for (int i = 0; i < args.length; i++) {
    String[] nameValue = args[i].split("=");
    if (nameValue.length != 2) {
        System.err.println("Command line parameter is not in the form key=value: " + args[i]);
        System.exit(-1);
    configParameters.put(nameValue[0], nameValue[1]);
...
MapparseCommandLineArguments(String[] args)
A simpler form of command line argument parsing.
Map<String, String> result = new HashMap<>();
String key, value;
for (int i = 0; i < args.length; i++) {
    key = args[i];
    if (key.charAt(0) == '-') {
        if (i + 1 < args.length) {
            value = args[i + 1];
            if (value.charAt(0) != '-') {
...
MapparseCommandLineArguments(String[] args)
As the name implies, this method parses command line arguments, provided in the standard form of an array of String-objects into a Map.
HashMap retMap = new HashMap();
String lastArg = null;
for (int i = 0; i < args.length; i++) {
    String arg = args[i];
    if (arg.startsWith("-")) {
        arg = arg.substring(1, arg.length());
        String[] values = arg.split("=", 2);
        lastArg = arg;
...
HashMapparseLines(String[] lines)
parse Lines
HashMap<String, String> adbEnv = new HashMap<>();
for (String oneAppend : lines) {
    String[] allAppends = oneAppend.split("\n");
    for (int i = 0; i < allAppends.length; i++) {
        String setEnvVarCommand = getLineType(allAppends[i]);
        if (setEnvVarCommand != null) {
            String setEnvVarDelim = getDelim(setEnvVarCommand);
            String lineRemainder = allAppends[i].trim().substring(setEnvVarCommand.length());
...
Map>parseProgramArguments(String[] args)
Parses command line arguments to map.
Map<String, List<String>> parsedArgs = new LinkedHashMap<String, List<String>>();
String lastParam = "_";
for (String arg : args) {
    if (arg.startsWith("-")) {
        if (!lastParam.equals(arg)) {
            parsedArgs.put(arg, new ArrayList<String>());
            lastParam = arg;
    } else {
        if (lastParam.equals("_")) {
            if (!parsedArgs.containsKey("_")) {
                parsedArgs.put("_", new ArrayList<String>());
        parsedArgs.get(lastParam).add(arg);
return parsedArgs;
MapparseProviderOptions(String[] options)
Creates a Map of Strings, which contain provider specific options.
Map<String, String> providerOptions = new HashMap<String, String>();
if (options != null && options.length > 0) {
    for (String option : options) {
        if (option.contains("=")) {
            String key = option.substring(0, option.indexOf("="));
            String value = option.substring(option.lastIndexOf("=") + 1);
            providerOptions.put(key, value);
return providerOptions;