Not sure what the problematic loop is intended to do as it seems that you are checking for the url
passed in as a parameter to exist in the HashObject
of the current iteration through the list, and if not found in there insert a new HashObject
in the list which has its url
value as that of the passed in url
. If none of the existing HashObject
s have the same value as the passed in url
, then you will be insterting multiple HashObject
s in the list with the same value for title
, term
, url
etc.
If this is indeed what you need then use a ListIterator
for adding while iterating through the list. You can read more about the add method of ListIterator
.
ListIterator listIter = list.listIterator();
while (listIter.hasNext()) {
HashObject value = listIter.next();
if(url.equals(value.getUrl())){
value.setFrequency();
}
if(!url.equals(value.getUrl())){
listIter.add(new HashObject(title, term, url, 1, 1));
}
}
But maybe on discovering that none of your HashObject
s in the list have the passed in url, you want to insert a new HashObject
with that url only once. In that case the code above will have to change.