public static Map < String , String > arrayToMap ( String [ ] args ) { if ( args . length % 2 != 0 ) { throw new IllegalArgumentException ( "Must pass in an even number of args, one key per value." ) ; } Map < String , String > ret = new HashMap <> ( ) ; for ( int i = 0 ; i < args . length ; i += 2 ) { ret . put ( args [ i ] , args [ i + 1 ] ) ; } return ret ; }
Helper to convert an alternating key1 value1 key2 value2 ... array into a map .