I wrote the code that pulls all the links on a web page. I check with Arraylist to prevent the same link from appearing. But I get stackoverflow error if there are too many links on the site. I keep links in Arraylist for later use. How do I avoid this stackoverflow error? Could the cause of the problem be arraylist?
static ArrayList<String> linkleriTut = new ArrayList();
public void linkleriCek(String url, String taramaTuru) throws IOException{
try {
Document doc = Jsoup.connect(url).get();
Elements linkler = doc.select("a[href]");
for (Element link : linkler) {
if (!linkleriTut.contains(link.attr("abs:href"))) {
linkleriTut.add(link.attr("abs:href"));
}
}
}
}
catch (Exception e) {
}
if (taramaTuru.equals("Detaylı Tarama")) {
while (k < linkleriTut.size()) {
k++;
linkleriCek(linkleriTut.get(k), taramaTuru);
}
}