Java JSONArray: Add Data Guide

To add data to a JSONArray object, you can use the put method of JSONArray. For example:

JSONArray jsonArray = new JSONArray();
jsonArray.put("apple");
jsonArray.put("banana");
jsonArray.put("orange");

In the example above, we created a JSONArray object and added three string data to the array by calling the put method. Now the jsonArray contains three elements which are “apple”, “banana”, and “orange”.

bannerAds