code: int getInt(String[] args, int index) {
      int result = -1;
      if(index >= 0 && index < args.length) {
        try {
          result = Integer.parseInt(args[index]);
        }catch(NumberFormatException e) {
          result = -1;
        }
      }
      return result;
    }
docs: Utility function to parse a positive integer argument out of a String
  array at the given index.
  @param args String array containing element to find.
  @param index Index of array element to parse integer from.
  @return Integer parsed, or -1 if error.