JSONObject is an unordered collection of name pairs and value pairs. Some important methods of JSONArray are accumulate(), put(), opt(), append(), write(), etc. accumulate() The method accumulates the values under the key. This method is similar to the put() method, except that there are existing objects stored under the key. Then the JSONArray can be stored under the key to save all Cumulative value. If an existing JSONArray exists, new values can be added.
public JSONObject accumulate(java.lang.String key, java.lang.Object value) throws JSONException
import org.json.*; public class JSONAccumulateMethodTest { public static void main(String[] args) throws JSONException { JSONObject jsonObj = new JSONObject(); jsonObj.accumulate("Technology", "Java"); jsonObj.accumulate("Technology", "Python"); jsonObj.accumulate("Technology", "Spark"); jsonObj.accumulate("Technology", "Selenium"); jsonObj.accumulate("Technology", ".Net"); System.out.println(jsonObj.toString(3)); } }
{"Technology": [ "Java", "Python", "Spark", "Selenium", ".Net" ]}
The above is the detailed content of What is the importance of accumulate() method in Java?. For more information, please follow other related articles on the PHP Chinese website!