I was working on a program that was outputting glossary terms and definitions in HTML and I want to vary the output based on whether the definition I'm checking has a keyword. To do this I have an ArrayList holding all the keywords I'm looking out for and I was trying to use a foreach loop but it wasn't really working right. Is there a better way to do this. Can someone offer me any pointers with this. I feel it shouldn't be THAT hard. With the HTML bit, I'm trying to output the leading words before the keyword (the keyword is supposed to be HREFED), and then continue past the keyword checking for any more keywords in the definition.
BY THE WAY: checkValues is my ArrayList and valueTwo is the definition.
This is what I have so far:
for(String getTerm : checkValues){
String correct = getTerm + " ";
if (valueTwo.contains(correct)) {
int foundTermPosition = valueTwo.indexOf(correct);
lead = valueTwo.substring(0, foundTermPosition-1);
index = valueTwo.length() - lead.length();
leftOver = valueTwo.substring(foundTermPosition+correct.length(), valueTwo.length());
out.write(lead);
out.write("<A HREF=\"#" + correct + "\">" + correct + "</A>");
out.write(leftOver + "\n");
}
else
{
out.write(valueTwo);
}
}