Adding an item to arralist which is already saved in shared preferences in android
<p>I am having an array list which is already stored in shared preferences.I want to add another item in array list.
Whenever i am trying to add an item in array list it is removing all the previous data stored in arraylist</p>

<p>How can i add item without removing the previous data in shared preferences </p>

<pre><code>ArrayList&lt;String&gt; cartArrayListID,cartArrayListName,cartArrayListPrice,cartArrayListImage;
    String cartID,cartName,cartPrice,cartImage;
cartArrayListID=new ArrayList&lt;&gt;();
        cartArrayListName=new ArrayList&lt;&gt;();
        cartArrayListPrice=new ArrayList&lt;&gt;();
        cartArrayListImage=new ArrayList&lt;&gt;();
cartArrayListID.add(cartID);
                cartArrayListName.add(cartName);
                cartArrayListPrice.add(cartPrice);
                cartArrayListImage.add(cartImage);
SharedPreferences sprefCart=getSharedPreferences("CARTINFO", Context.MODE_PRIVATE);
                SharedPreferences.Editor editorCart=sprefCart.edit();
                Gson gson = new Gson();
                String id_=gson.toJson(cartArrayListID);
                String name_=gson.toJson(cartArrayListName);
                String price_=gson.toJson(cartArrayListPrice);
                String image_=gson.toJson(cartArrayListImage);
                editorCart.putString("ID", id_);
                editorCart.putString("NAME", name_);
                editorCart.putString("PRICE", price_);
                editorCart.putString("IMAGE", image_);
                editorCart.apply();
                Toast.makeText(ProductActivity.this, "Added to cart", Toast.LENGTH_SHORT).show();
</code></pre>