How to update RecyclerView in Android

1) Insert single item at any position:String value = “India”;int index = 2;dataList.add(index, value);adapter.notifyItemInserted(index);This will add India at position 2.2) Insert multiple items:int  index   = 3;dataList.add(index,”Australia”);dataList.add(index,”England”);dataList.add(index,”South Africa”);adapter.notifyItemRangeInserted( index,  dataList.size());Australia will be listed at position 3, England will be listed at position 4 and South Africa will be listed at position 53) Remove single item from any position:int  index = 4;dataList.remove( index);adapter.notifyItemRemoved(index);This will remove England from the RecyclerView.4) Remove multiple items:int startIndex = 2;int endIndex = 4;int count = endIndex – startIndex;dataList.subList(startIndex, endIndex).clear();adapter.notifyItemRangeRemoved(startIndex, count);This will remove 2 items at position 2 and 3.5) Remove all items:dataList.clear();adapter.notifyDataSetChanged();6) Replace old list with new list:dataList.clear();// add new listArrayList newList = new ArrayList();newList.add(“Sri Lanka”);newList.add(“Bangladesh”);newList.add(“Pakistan”);dataList.addAll(newList);// notify adapteradapter.notifyDataSetChanged();This will replace the old values with new one.7) Update single item:String newValue = “India”;int updateIndex = 2;dataList.set(updateIndex, newValue);adapter.notifyItemChanged(updateIndex);This is replace Pakistan with India8) Change position of a single item:int fromPosition = 2;int toPosition = 0;// update data arrayString item =  dataList.get(fromPosition);dataList.remove(fromPosition);dataList.add(toPosition, item);// notify adapteradapter.notifyItemMoved(fromPosition, toPosition);This will move India from Postion 3 to 0.  This are the various ways you can update recyclerview