title: How to convert a collection/ array into JSONArray using stream in java 8
body: <p>Im having a double array , I need to convert the array into a <code>JSONArray</code> using java <code>streams</code>. I tried using forEach (shared mutability) which leads to loss of data.</p>
  <pre><code>public static JSONArray arrayToJson(double[] array) throws JSONException{
      JSONArray jsonArray = new JSONArray();
      
      Arrays.stream(array)
           .forEach(jsonArray::put);  
  
      return jsonArray;
  }
  </code></pre>
  <p>Is there any way I could to create <code>JSONArray</code> using streams?</p>