Skip to content

Commit 3645f91

Browse files
author
John J. Aylward
committed
change JSONArray(Collection) constructor to use the default capacity when a null collection is passed
1 parent 9c09275 commit 3645f91

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

JSONArray.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ public JSONArray(String source) throws JSONException {
154154
* A Collection.
155155
*/
156156
public JSONArray(Collection<?> collection) {
157-
this.myArrayList = new ArrayList<Object>(collection == null ? 0 : collection.size());
158-
if (collection != null) {
157+
if (collection == null) {
158+
this.myArrayList = new ArrayList<Object>();
159+
} else {
160+
this.myArrayList = new ArrayList<Object>(collection.size());
159161
for (Object o: collection){
160162
this.myArrayList.add(JSONObject.wrap(o));
161163
}

0 commit comments

Comments
 (0)