title: Is there a way, I can empty the whole JSONObject -- java
body: <p>I have to populate a json object like this, let say it is named detailJSON:</p>
  
  <pre><code>{"amount": "5.00", "ac_no": "123456" } 
  </code></pre>
  
  <p>I do it this way:</p>
  
  <pre><code>detailJSON.put("amount","5.00");
  detailJSON.put("ac_no","123456");
  </code></pre>
  
  <p>After this, the detail is entered in some shared preferences, and now I want to <strong>clear</strong> this JSONObject and use the same detailJSON object to store another json (with different keys), this way:</p>
  
  <pre><code>{"amount":"6.00", "loan_no":"123456"}
  </code></pre>
  
  <p>I know there is a method, remove(), that removes the particular key and corresponding value. </p>
  
  <p><strong>This works</strong>:</p>
  
  <pre><code>detailJSON.remove("amount");
  detailJSON.remove("ac_no");
  </code></pre>
  
  <p>and then use it --</p>
  
  <pre><code>detailJSON.put("amount","6.0");
  detailJSON.put("loan_no","123456");
  </code></pre>
  
  <p>Now this is a very simple example. In the code I'm working on, I have a lot of keys, so using remove actually increases the LOC. Also, each time before removing I need to check whether JSONObject <code>has</code> that particular key or not. </p>
  
  <p>Is there any other way, I can implement clearing of the JSONObject?? </p>
  
  <p>I tried </p>
  
  <pre><code>detailJSON=null ;
  detailJSON=new JSONObject();
  </code></pre>
  
  <p>But it does not work. </p>
  
  <p>I am basically in search of something like clear() method, if exists.</p>