I have a java list of URLs. I wish to call a function for each URL in the list. And this function adds URL to the list. Is it possible to loop over all the URLs including newly added URLs in the list?
for(String links: urls) {
ar = getNews(links);
}
inside getNews() there is:
urls.add(json.optString("next"));
I did this successfully using recursion. By calling:
getNews(json.optString("next"));
inside getNews()
for i = 0; ...), since it allows concurrent modification, and checks for the exit condition at every iteration