I'm using a RecycleView with a Gridlayoutmanager. My app loads a lot of items when the user scrolls down.
LinkedList has a good performance when adding new elements, while my ArrayList would need to get constantly resized.
But I'm not sure about what RecycleView does in the background which would work better with an ArrayList and/or a LinkedList.
My adapter would be:
public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.PhotosViewHolder> {
private Context context;
private List<Photo> items;
public PhotosAdapter(Context context, List<Photo> items) {
this.context = context;
this.items = items;
}
//other code here
public void addAll(List<Photo> newItems) {
int beforeSize = items.size()-1;
items.addAll(newItems);
notifyItemRangeInserted(beforeSize, newItems.size());
}
}
So when I create a new empty adapter I can either do this:
new PhotosAdapter(getContext(), new ArrayList<Photo>());
or this:
new PhotosAdapter(getContext(), new LinkedList<Photo>());
And when adding new elements simply:
adapter.addAll(myPhotos);
So would a LinkedList work better in this case? What about RecycleView's optimalized scrolling? Does that work better with an ArrayList or a LinkedList?