Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/org/json/JSONArray#pubctors) \| [Methods](https://developer.android.com/reference/org/json/JSONArray#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/org/json/JSONArray#inhmethods)

# JSONArray

` public class JSONArray `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | org.json.JSONArray |

<br />

*** ** * ** ***

A dense indexed sequence of values. Values may be any mix of `https://developer.android.com/reference/org/json/JSONObject`, other `https://developer.android.com/reference/org/json/JSONArray`, Strings, Booleans, Integers, Longs, Doubles, `null` or `https://developer.android.com/reference/org/json/JSONObject#NULL`. Values may not be `https://developer.android.com/reference/java/lang/Double#isNaN()`, `https://developer.android.com/reference/java/lang/Double#isInfinite()`, or of any type not listed here.

`JSONArray` has the same type coercion behavior and optional/mandatory accessors as `https://developer.android.com/reference/org/json/JSONObject`. See that class' documentation for details.

**Warning:** this class represents null in two incompatible ways: the standard Java `null` reference, and the sentinel value `https://developer.android.com/reference/org/json/JSONObject#NULL`. In particular, `get` fails if the requested index holds the null reference, but succeeds if it holds `JSONObject.NULL`.

Instances of this class are not thread safe. Although this class is nonfinal, it was not designed for inheritance and should not be subclassed. In particular, self-use by overridable methods is not specified. See *Effective Java* Item 17, "Design and Document or inheritance or else prohibit it" for further information.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/org/json/JSONArray#JSONArray()() ` Creates a `JSONArray` with no values. |
| ` https://developer.android.com/reference/org/json/JSONArray#JSONArray(java.lang.Object)(https://developer.android.com/reference/java/lang/Object array) ` Creates a new `JSONArray` with values from the given primitive array. |
| ` https://developer.android.com/reference/org/json/JSONArray#JSONArray(java.lang.String)(https://developer.android.com/reference/java/lang/String json) ` Creates a new `JSONArray` with values from the JSON string. |
| ` https://developer.android.com/reference/org/json/JSONArray#JSONArray(java.util.Collection)(https://developer.android.com/reference/java/util/Collection<E> copyFrom) ` Creates a new `JSONArray` by copying all values from the given collection. |
| ` https://developer.android.com/reference/org/json/JSONArray#JSONArray(org.json.JSONTokener)(https://developer.android.com/reference/org/json/JSONTokener readFrom) ` Creates a new `JSONArray` with values from the next array in the tokener. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/org/json/JSONArray#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Indicates whether some other object is "equal to" this one. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/org/json/JSONArray#get(int)(int index) ` Returns the value at `index`. |
| ` boolean` | ` https://developer.android.com/reference/org/json/JSONArray#getBoolean(int)(int index) ` Returns the value at `index` if it exists and is a boolean or can be coerced to a boolean. |
| ` double` | ` https://developer.android.com/reference/org/json/JSONArray#getDouble(int)(int index) ` Returns the value at `index` if it exists and is a double or can be coerced to a double. |
| ` int` | ` https://developer.android.com/reference/org/json/JSONArray#getInt(int)(int index) ` Returns the value at `index` if it exists and is an int or can be coerced to an int. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#getJSONArray(int)(int index) ` Returns the value at `index` if it exists and is a `JSONArray`. |
| ` https://developer.android.com/reference/org/json/JSONObject` | ` https://developer.android.com/reference/org/json/JSONArray#getJSONObject(int)(int index) ` Returns the value at `index` if it exists and is a `JSONObject`. |
| ` long` | ` https://developer.android.com/reference/org/json/JSONArray#getLong(int)(int index) ` Returns the value at `index` if it exists and is a long or can be coerced to a long. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/org/json/JSONArray#getString(int)(int index) ` Returns the value at `index` if it exists, coercing it if necessary. |
| ` int` | ` https://developer.android.com/reference/org/json/JSONArray#hashCode()() ` Returns a hash code value for the object. |
| ` boolean` | ` https://developer.android.com/reference/org/json/JSONArray#isNull(int)(int index) ` Returns true if this array has no value at `index`, or if its value is the `null` reference or `https://developer.android.com/reference/org/json/JSONObject#NULL`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/org/json/JSONArray#join(java.lang.String)(https://developer.android.com/reference/java/lang/String separator) ` Returns a new string by alternating this array's values with `separator`. |
| ` int` | ` https://developer.android.com/reference/org/json/JSONArray#length()() ` Returns the number of values in this array. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/org/json/JSONArray#opt(int)(int index) ` Returns the value at `index`, or null if the array has no value at `index`. |
| ` boolean` | ` https://developer.android.com/reference/org/json/JSONArray#optBoolean(int)(int index) ` Returns the value at `index` if it exists and is a boolean or can be coerced to a boolean. |
| ` boolean` | ` https://developer.android.com/reference/org/json/JSONArray#optBoolean(int,%20boolean)(int index, boolean fallback) ` Returns the value at `index` if it exists and is a boolean or can be coerced to a boolean. |
| ` double` | ` https://developer.android.com/reference/org/json/JSONArray#optDouble(int)(int index) ` Returns the value at `index` if it exists and is a double or can be coerced to a double. |
| ` double` | ` https://developer.android.com/reference/org/json/JSONArray#optDouble(int,%20double)(int index, double fallback) ` Returns the value at `index` if it exists and is a double or can be coerced to a double. |
| ` int` | ` https://developer.android.com/reference/org/json/JSONArray#optInt(int)(int index) ` Returns the value at `index` if it exists and is an int or can be coerced to an int. |
| ` int` | ` https://developer.android.com/reference/org/json/JSONArray#optInt(int,%20int)(int index, int fallback) ` Returns the value at `index` if it exists and is an int or can be coerced to an int. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#optJSONArray(int)(int index) ` Returns the value at `index` if it exists and is a `JSONArray`. |
| ` https://developer.android.com/reference/org/json/JSONObject` | ` https://developer.android.com/reference/org/json/JSONArray#optJSONObject(int)(int index) ` Returns the value at `index` if it exists and is a `JSONObject`. |
| ` long` | ` https://developer.android.com/reference/org/json/JSONArray#optLong(int)(int index) ` Returns the value at `index` if it exists and is a long or can be coerced to a long. |
| ` long` | ` https://developer.android.com/reference/org/json/JSONArray#optLong(int,%20long)(int index, long fallback) ` Returns the value at `index` if it exists and is a long or can be coerced to a long. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/org/json/JSONArray#optString(int)(int index) ` Returns the value at `index` if it exists, coercing it if necessary. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/org/json/JSONArray#optString(int,%20java.lang.String)(int index, https://developer.android.com/reference/java/lang/String fallback) ` Returns the value at `index` if it exists, coercing it if necessary. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(int)(int value) ` Appends `value` to the end of this array. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(long)(long value) ` Appends `value` to the end of this array. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(int,%20boolean)(int index, boolean value) ` Sets the value at `index` to `value`, null padding this array to the required length if necessary. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(double)(double value) ` Appends `value` to the end of this array. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(int,%20java.lang.Object)(int index, https://developer.android.com/reference/java/lang/Object value) ` Sets the value at `index` to `value`, null padding this array to the required length if necessary. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(int,%20long)(int index, long value) ` Sets the value at `index` to `value`, null padding this array to the required length if necessary. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(int,%20int)(int index, int value) ` Sets the value at `index` to `value`, null padding this array to the required length if necessary. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(boolean)(boolean value) ` Appends `value` to the end of this array. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(int,%20double)(int index, double value) ` Sets the value at `index` to `value`, null padding this array to the required length if necessary. |
| ` https://developer.android.com/reference/org/json/JSONArray` | ` https://developer.android.com/reference/org/json/JSONArray#put(java.lang.Object)(https://developer.android.com/reference/java/lang/Object value) ` Appends `value` to the end of this array. |
| ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/org/json/JSONArray#remove(int)(int index) ` Removes and returns the value at `index`, or null if the array has no value at `index`. |
| ` https://developer.android.com/reference/org/json/JSONObject` | ` https://developer.android.com/reference/org/json/JSONArray#toJSONObject(org.json.JSONArray)(https://developer.android.com/reference/org/json/JSONArray names) ` Returns a new object whose values are the values in this array, and whose names are the values in `names`. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/org/json/JSONArray#toString()() ` Encodes this array as a compact JSON string, such as: ``` [94043,90210] ``` <br /> |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/org/json/JSONArray#toString(int)(int indentSpaces) ` Encodes this array as a human readable JSON string for debugging, such as: ``` [ 94043, 90210 ] ``` <br /> |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### JSONArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray ()
```

Creates a `JSONArray` with no values.

<br />

### JSONArray

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray (Object array)
```

Creates a new `JSONArray` with values from the given primitive array.

<br />

| Parameters ||
|---|---|
| `array` | `Object` <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### JSONArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray (String json)
```

Creates a new `JSONArray` with values from the JSON string.

<br />

| Parameters ||
|---|---|
| `json` | `String`: a JSON-encoded string containing an array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the parse fails or doesn't yield a `JSONArray`. |

### JSONArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray (Collection<E> copyFrom)
```

Creates a new `JSONArray` by copying all values from the given collection.

<br />

| Parameters ||
|---|---|
| `copyFrom` | `Collection`: a collection whose values are of supported types. Unsupported values are not permitted and will yield an array in an inconsistent state. <br /> |

### JSONArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray (JSONTokener readFrom)
```

Creates a new `JSONArray` with values from the next array in the tokener.

<br />

| Parameters ||
|---|---|
| `readFrom` | `JSONTokener`: a tokener whose nextValue() method will yield a `JSONArray`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the parse fails or doesn't yield a `JSONArray`. |

## Public methods

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object o)
```

Indicates whether some other object is "equal to" this one.

The `equals` method implements an equivalence relation on non-null object references:

- It is *reflexive*: for any non-null reference value `x`, `x.equals(x)` should return `true`.
- It is *symmetric*: for any non-null reference values `x` and `y`, `x.equals(y)` should return `true` if and only if `y.equals(x)` returns `true`.
- It is *transitive*: for any non-null reference values `x`, `y`, and `z`, if `x.equals(y)` returns `true` and `y.equals(z)` returns `true`, then `x.equals(z)` should return `true`.
- It is *consistent*: for any non-null reference values `x` and `y`, multiple invocations of `x.equals(y)` consistently return `true` or consistently return `false`, provided no information used in `equals` comparisons on the objects is modified.
- For any non-null reference value `x`, `x.equals(null)` should return `false`.

An equivalence relation partitions the elements it operates on into *equivalence classes*; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

<br />

| Parameters ||
|---|---|
| `o` | `Object`: the reference object with which to compare. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this object is the same as the obj argument; `false` otherwise. <br /> |

### get

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object get (int index)
```

Returns the value at `index`.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if this array has no value at `index`, or if that value is the `null` reference. This method returns normally if the value is `JSONObject#NULL`. |

### getBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean getBoolean (int index)
```

Returns the value at `index` if it exists and is a boolean or can be coerced to a boolean.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the value at `index` doesn't exist or cannot be coerced to a boolean. |

### getDouble

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double getDouble (int index)
```

Returns the value at `index` if it exists and is a double or can be coerced to a double.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `double` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the value at `index` doesn't exist or cannot be coerced to a double. |

### getInt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getInt (int index)
```

Returns the value at `index` if it exists and is an int or can be coerced to an int.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `int` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the value at `index` doesn't exist or cannot be coerced to a int. |

### getJSONArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray getJSONArray (int index)
```

Returns the value at `index` if it exists and is a `JSONArray`.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the value doesn't exist or is not a `JSONArray`. |

### getJSONObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONObject getJSONObject (int index)
```

Returns the value at `index` if it exists and is a `JSONObject`.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONObject` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the value doesn't exist or is not a `JSONObject`. |

### getLong

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long getLong (int index)
```

Returns the value at `index` if it exists and is a long or can be coerced to a long.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if the value at `index` doesn't exist or cannot be coerced to a long. |

### getString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String getString (int index)
```

Returns the value at `index` if it exists, coercing it if necessary.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` | if no such value exists. |

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by `https://developer.android.com/reference/java/util/HashMap`.

The general contract of `hashCode` is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the `hashCode` method must consistently return the same integer, provided no information used in `equals` comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce the same integer result.
- It is *not* required that if two objects are unequal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

| Returns ||
|---|---|
| `int` | a hash code value for this object. <br /> |

### isNull

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isNull (int index)
```

Returns true if this array has no value at `index`, or if its value is the `null` reference or `https://developer.android.com/reference/org/json/JSONObject#NULL`.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### join

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String join (String separator)
```

Returns a new string by alternating this array's values with `separator`. This array's string values are quoted and have their special characters escaped. For example, the array containing the strings '12" pizza', 'taco' and 'soda' joined on '+' returns this:

```
"12\" pizza"+"taco"+"soda"
```

<br />

<br />

| Parameters ||
|---|---|
| `separator` | `String` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### length

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int length ()
```

Returns the number of values in this array.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### opt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object opt (int index)
```

Returns the value at `index`, or null if the array has no value at `index`.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | <br /> |

### optBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean optBoolean (int index)
```

Returns the value at `index` if it exists and is a boolean or can be coerced to a boolean. Returns false otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### optBoolean

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean optBoolean (int index, 
                boolean fallback)
```

Returns the value at `index` if it exists and is a boolean or can be coerced to a boolean. Returns `fallback` otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `fallback` | `boolean` <br /> |

| Returns ||
|---|---|
| `boolean` | <br /> |

### optDouble

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double optDouble (int index)
```

Returns the value at `index` if it exists and is a double or can be coerced to a double. Returns `NaN` otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `double` | <br /> |

### optDouble

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public double optDouble (int index, 
                double fallback)
```

Returns the value at `index` if it exists and is a double or can be coerced to a double. Returns `fallback` otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `fallback` | `double` <br /> |

| Returns ||
|---|---|
| `double` | <br /> |

### optInt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int optInt (int index)
```

Returns the value at `index` if it exists and is an int or can be coerced to an int. Returns 0 otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `int` | <br /> |

### optInt

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int optInt (int index, 
                int fallback)
```

Returns the value at `index` if it exists and is an int or can be coerced to an int. Returns `fallback` otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `fallback` | `int` <br /> |

| Returns ||
|---|---|
| `int` | <br /> |

### optJSONArray

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray optJSONArray (int index)
```

Returns the value at `index` if it exists and is a `JSONArray`. Returns null otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | <br /> |

### optJSONObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONObject optJSONObject (int index)
```

Returns the value at `index` if it exists and is a `JSONObject`. Returns null otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONObject` | <br /> |

### optLong

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long optLong (int index)
```

Returns the value at `index` if it exists and is a long or can be coerced to a long. Returns 0 otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

### optLong

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public long optLong (int index, 
                long fallback)
```

Returns the value at `index` if it exists and is a long or can be coerced to a long. Returns `fallback` otherwise.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `fallback` | `long` <br /> |

| Returns ||
|---|---|
| `long` | <br /> |

### optString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String optString (int index)
```

Returns the value at `index` if it exists, coercing it if necessary. Returns the empty string if no such value exists.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### optString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String optString (int index, 
                String fallback)
```

Returns the value at `index` if it exists, coercing it if necessary. Returns `fallback` if no such value exists.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `fallback` | `String` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (int value)
```

Appends `value` to the end of this array.

<br />

| Parameters ||
|---|---|
| `value` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (long value)
```

Appends `value` to the end of this array.

<br />

| Parameters ||
|---|---|
| `value` | `long` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (int index, 
                boolean value)
```

Sets the value at `index` to `value`, null padding this array to the required length if necessary. If a value already exists at `index`, it will be replaced.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `value` | `boolean` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (double value)
```

Appends `value` to the end of this array.

<br />

| Parameters ||
|---|---|
| `value` | `double`: a finite value. May not be `https://developer.android.com/reference/java/lang/Double#isNaN()` or `https://developer.android.com/reference/java/lang/Double#isInfinite()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (int index, 
                Object value)
```

Sets the value at `index` to `value`, null padding this array to the required length if necessary. If a value already exists at `index`, it will be replaced.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `value` | `Object`: a `https://developer.android.com/reference/org/json/JSONObject`, `https://developer.android.com/reference/org/json/JSONArray`, String, Boolean, Integer, Long, Double, `https://developer.android.com/reference/org/json/JSONObject#NULL`, or `null`. May not be `https://developer.android.com/reference/java/lang/Double#isNaN()` or `https://developer.android.com/reference/java/lang/Double#isInfinite()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (int index, 
                long value)
```

Sets the value at `index` to `value`, null padding this array to the required length if necessary. If a value already exists at `index`, it will be replaced.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `value` | `long` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (int index, 
                int value)
```

Sets the value at `index` to `value`, null padding this array to the required length if necessary. If a value already exists at `index`, it will be replaced.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `value` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (boolean value)
```

Appends `value` to the end of this array.

<br />

| Parameters ||
|---|---|
| `value` | `boolean` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (int index, 
                double value)
```

Sets the value at `index` to `value`, null padding this array to the required length if necessary. If a value already exists at `index`, it will be replaced.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |
| `value` | `double`: a finite value. May not be `https://developer.android.com/reference/java/lang/Double#isNaN()` or `https://developer.android.com/reference/java/lang/Double#isInfinite()`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### put

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONArray put (Object value)
```

Appends `value` to the end of this array.

<br />

| Parameters ||
|---|---|
| `value` | `Object`: a `https://developer.android.com/reference/org/json/JSONObject`, `https://developer.android.com/reference/org/json/JSONArray`, String, Boolean, Integer, Long, Double, `https://developer.android.com/reference/org/json/JSONObject#NULL`, or `null`. May not be `https://developer.android.com/reference/java/lang/Double#isNaN()` or `https://developer.android.com/reference/java/lang/Double#isInfinite()`. Unsupported values are not permitted and will cause the array to be in an inconsistent state. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONArray` | this array. <br /> |

### remove

Added in [API level 19](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Object remove (int index)
```

Removes and returns the value at `index`, or null if the array has no value at `index`.

<br />

| Parameters ||
|---|---|
| `index` | `int` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | <br /> |

### toJSONObject

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public JSONObject toJSONObject (JSONArray names)
```

Returns a new object whose values are the values in this array, and whose names are the values in `names`. Names and values are paired up by index from 0 through to the shorter array's length. Names that are not strings will be coerced to strings. This method returns null if either array is empty.

<br />

| Parameters ||
|---|---|
| `names` | `JSONArray` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONObject` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Encodes this array as a compact JSON string, such as:

```
[94043,90210]
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString (int indentSpaces)
```

Encodes this array as a human readable JSON string for debugging, such as:

```
[
    94043,
    90210
]
```

<br />

<br />

| Parameters ||
|---|---|
| `indentSpaces` | `int`: the number of spaces to indent for each level of nesting. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/org/json/JSONException` |   |