My code using many array list with custom model, now i want to store all array list in one Seprate arrayList, how it is possible.
public ArrayList<TwitterFeedCustomModel> mFacebookFeedCustomModelArrayList = new ArrayList<>(); public ArrayList<TwitterFeedCustomModel> mTwitterFeedCustomModelArrayList = new ArrayList<TwitterFeedCustomModel>(); public ArrayList<LinkedInFeedCustomModel> mLinkedInFeedCustomModelArrayList = new ArrayList<LinkedInFeedCustomModel>(); public ArrayList<InstagramFeedCustomModel> mInstagramFeedCustomModelArrayList = new ArrayList<InstagramFeedCustomModel>(); public ArrayList<YouTubeFeedCustomModel> mYouTubeFeedCustomModelArrayList = new ArrayList<YouTubeFeedCustomModel>(); public ArrayList<BlogFeedCustomModel> mBlogFeedCustomModelArrayList = new ArrayList<BlogFeedCustomModel>();All arraylist have seprate data, now i want to store all array list data in one arrayList, how we can do please help me.
2 Answers
ArrayList<Object> singleArrayList = new ArrayList<> ();
singleArrayList.add(mFacebookFeedCustomModelArrayList);
singleArrayList.add(mTwitterFeedCustomModelArrayList);
singleArrayList.add(mLinkedInFeedCustomModelArrayList);
......
while retrieving data you have to do type check.
11 Comments
Hitesh Tarbundiya
after above implementation, how to get all data ?
Aman Srivastava
int index =0; if( singleArrayList.get(index) instanceof ArrayList<TwitterFeedCustomModel>) { mFacebookFeedCustomModelArrayList = singleArrayList.get(index) ; ........} like wise.Hitesh Tarbundiya
hi friend, your solution is correct, but i want to all arraylist data in one arraylist, on that single array list iwant to perform many operation like sorting, filter etc, so it is possible to without object, because this one is not help full for me
Hitesh Tarbundiya
this one is doesn't meaning for implementation, because we check every time which object is, so same as my implementation,
Aman Srivastava
ok. ArrayList<Object> singleArrayList = new ArrayList<> (); singleArrayList.addAll(mFacebookFeedCustomModelArrayList);
|
genericsfor creating the motherArrayList?