Java Args Parse parseArgs(String[] args)

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

Description

parse Args

License

Open Source License

Declaration

public static HashMap parseArgs(String[] args) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

public class Main {
    public static HashMap parseArgs(String[] args) {
        HashMap results = new HashMap();
        for (int i = 0; i <= args.length - 1; i++) {
            String value = "";
            if (args[i].indexOf("-") == 0) {
                if (args[i].length() == 2) {
                    try {
                        value = args[i + 1];
                    } catch (Exception e) {
                        System.out.println("Unable to get value after flag '" + args[i] + "'");
                    }/*from   w w w .  j av a2s .  c om*/
                } else if (args[i].length() > 2) {
                    value = args[i].substring(2);
                } else if (args[i].length() == 1) {
                    System.out.println("Invalid flag");
                }
                if (args[i].charAt(1) == 'p') {
                    results.put("-p", value);
                } else if (args[i].charAt(1) == 'u') {
                    results.put("-u", value);
                }
            }
        }
        return results;
    }
}

Related

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