public static Map parseCommandLineArguments(String[] args){
  Map<String,String> result=new HashMap<String,String>();
  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) != '-') {
          result.put(key,value);
          i++;
        }
 else {
          result.put(key,null);
        }
      }
 else {
        result.put(key,null);
      }
    }
  }
  return result;
}

public static Map parseCommandLineArguments ( String [ ] args ) { Map < String , String > result = new HashMap < String , String > ( ) ; 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 ) != '-' ) { result . put ( key , value ) ; i ++ ; } else { result . put ( key , null ) ; } } else { result . put ( key , null ) ; } } } return result ; }
a simpler form of command line argument parsing . dan thinks this is highly superior to the overly complexified code that comes before it . parses command line arguments into a map . arguments of the form - flag1 arg1 - flag2 - flag3 arg3 will be parsed so that the flag is a key in the map ( including the hyphen ) and the optional argument will be its value ( if present ) .
