I want to combine two ArrayList into a single one. These ArrayLists are NOT the type of "String". Object type is a custom class.
private ArrayList<NewsItem> newsList;
private ArrayList<NewsItem> eventList;
private ArrayList<NewsItem> combinedList;
This is how I am trying to combine those two ArrayLists:
private void combineArrays() {
if(newsList.size() > 0){
for (int i = 0; i<newsList.size(); i++){
NewsItem aBean = newsList.get(i);
combinedList.add(aBean);
}
}
if(eventList.size() > 0){
for (int i = 0; i<eventList.size(); i++){
NewsItem aBean = eventList.get(i);
combinedList.add(aBean);;
}
}
}
The app is crashing. What's the wrong with this approach?
newsList = new ArrayList<>();