public final class JSONArray extends AbstractSequentialList<Object>
This is an array in the JSON language.
Unlike other versions of JSONArrays I have encountered,
this does not just store the information in a
class that extends ArrayList
, or worse, uses one
and not implement List
. This extends
AbstractSequentialList
, but only one class variable,
a CharSequence
, so this is completly unrelated to
ArrayLists.
If you would like the speed of a diferent type of list, this
does implement a Collection constructor
,
and most other Collection
s have a Collection
constructor, so different implementations of
List
can be changed between at will.
modCount
Constructor and Description |
---|
JSONArray()
Creates an empty JSONArray
|
JSONArray(Collection<?> c)
Creates a JSONArray that contains the same objects as the collection
|
JSONArray(String unparsedString)
Creates a JSONArray based on the string
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Object o)
Adds the specified element at the specified index
|
boolean |
add(Object o)
Adds the specified Object to the JSONArray.
|
void |
clear()
This removes all the objects in the JSONArray.
|
Object |
get(int index)
Returns the element at the specified position in this list.
|
CharSequence |
getUnparsed()
returns a charsequence containing the unparsed verion of this array
|
boolean |
isEmpty()
returns true if the list is empty
|
static boolean |
isValid(String unparsedString)
Deprecated.
use
isValid.jsonArray(java.lang.String) instead |
ListIterator<Object> |
listIterator(int index) |
Object |
remove(int index) |
Object |
set(int index,
Object o) |
int |
size()
returns the number of elements in this JSONArray.
|
addAll, iterator
equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
public JSONArray()
public JSONArray(String unparsedString) throws ParseException, NullPointerException
unparsedString
- the string to decode into a JSONArrayParseException
- if unparsedString is invalidNullPointerException
- if unparsedString is nullpublic JSONArray(Collection<?> c) throws NullPointerException
c
- the collection to copy.NullPointerException
- if c is nullpublic CharSequence getUnparsed()
public ListIterator<Object> listIterator(int index)
listIterator
in interface List<Object>
listIterator
in class AbstractSequentialList<Object>
public int size()
size
in interface Collection<Object>
size
in interface List<Object>
size
in class AbstractCollection<Object>
public void clear()
clear
in interface Collection<Object>
clear
in interface List<Object>
clear
in class AbstractList<Object>
public boolean isEmpty()
isEmpty
in interface Collection<Object>
isEmpty
in interface List<Object>
isEmpty
in class AbstractCollection<Object>
size()
== 0
public boolean add(Object o) throws ClassCastException
The list of conversions is:
Map
to JSONObject
Collection
to JSONArray
CharSequence
to JSONString
Number
to Double
or Long
Boolean
and null
suffer no data loss in the conversion. All
other data types are unable to be added.add
in interface Collection<Object>
add
in interface List<Object>
add
in class AbstractList<Object>
o
- the Object to add.ClassCastException
- if the object is not one of the following types:
Boolean
Number
CharSequence
Collection
Map
public void add(int index, Object o) throws IndexOutOfBoundsException
add
in interface List<Object>
add
in class AbstractSequentialList<Object>
index
- the index to add the element ato
- the object to addIndexOutOfBoundsException
- if the index to add is out of the list's boundspublic Object get(int index) throws IndexOutOfBoundsException
get
in interface List<Object>
get
in class AbstractSequentialList<Object>
index
- the index of the value to getIndexOutOfBoundsException
- if the index is out of boundspublic Object set(int index, Object o) throws ClassCastException, IndexOutOfBoundsException
set
in interface List<Object>
set
in class AbstractSequentialList<Object>
ClassCastException
IndexOutOfBoundsException
public Object remove(int index)
public static boolean isValid(String unparsedString)
isValid.jsonArray(java.lang.String)
insteadunparsedString
- the string to testJSONArray(String)
can execute without errors
using the specified CharSequence