Here you can find the source of parseProgramArguments(String[] args)
Parameter | Description |
---|---|
args | Command line parameters array. |
public static Map<String, List<String>> parseProgramArguments(String[] args)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/* w ww.ja va2s. com*/ * Parses command line arguments to map. * Example: * program input output -m 128 912 -f ALL * Map Structure: * arguments * | * |--> '_' ['input','output'] * |--> '-m' ['128','912'] * |--> '-f' ['ALL'] * @param args Command line parameters array. * @return Argument list map. */ public static Map<String, List<String>> parseProgramArguments(String[] args) { 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; } }