Java Args Parse parseArg(String[] args)

Here you can find the source of parseArg(String[] args)

Description

parse Arg

License

Open Source License

Declaration

public static Map<String, String> parseArg(String[] args) 

Method Source Code


//package com.java2s;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static Map<String, String> parseArg(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        if (args == null || args.length == 0)
            return map;

        String lastKey = null;//from   w w  w  .  ja  va 2s.  c o m
        for (int i = 0; i < args.length; i++) {
            if (args[i] == null || args[i].equals(""))
                continue;
            if (args[i].startsWith("-")) {
                lastKey = args[i].substring(1);
            } else {
                if (lastKey != null) {
                    map.put(lastKey, args[i]);
                    lastKey = null;
                } else {
                    map.put(args[i], null);
                }
            }
        }
        if (lastKey != null)
            map.put(lastKey, null);
        return map;
    }
}

Related

  1. getPossibleCompletionsForGivenArgs(String[] args, String[] possibilitiesOfCompletion)
  2. getPossibleCompletionsForGivenArgs(String[] args, String[] possibilitiesOfCompletion)
  3. parse(String[] args)
  4. parse(String[] args)
  5. parseAndFillFittingValues(String[] prefixes, String[] values)
  6. parseArgs(String argvStart, String[] args)
  7. parseArgs(String[] args)
  8. parseArgs(String[] args)
  9. parseArgs(String[] args)