code: public JSONArray put(int index, Object value) throws JSONException {
          JSONObject.testValidity(value);
          if (index < 0) {
              throw new JSONException("JSONArray[" + index + "] not found.");
          }
          if (index < length()) {
              this.myArrayList.set(index, value);
          } else {
              while (index != length()) {
                  put(null);
              }
              put(value);
          }
          return this;
      }
docs: Put or replace an object value in the JSONArray. If the index is greater
  than the length of the JSONArray, then null elements will be added as
  necessary to pad it out.
  
  @param index The subscript.
  @param value The value to put into the array.
  @return this
  @throws JSONException If the index is negative or if the the value is
  an invalid number.