Q:

Writing Html file with java duplicates the entry

I have a program to do some calculations in excel and writing the output in a table tag in html file. I am adding rows dynamically at runtime depending on the number of results. While writing to html file the entries are not correct.
Suppose i have 50 rows in a html file. I am appening  49 rows at runtime in the template file and replacing values $id0, $age0, $time0.....$id49, $age49, $time49 in html file . For me first 10 rows are writing properly. From 11th row, the values are writing wrong. I am getting correct ones in the logs as well.
for(int i = 0; i < c; i++) {
  htmlString = htmlString.replace("$id"+i, cycle.get("id"+i).toString().trim());
  htmlString = htmlString.replace("$time"+i, cycle.get("time"+i).toString().trim());
  htmlString = htmlString.replace("$name"+i, cycle.get("name"+i).toString().trim())
}

The entry comes in html as

id  Name   age   time
  9   abc     8     8.08
  10  xyz    12     9.19
  11  xyz1   121    9.191
  12  xyz12  122    9.192

the values for id 11, 12 are wrong. It shows 10th id's values appended with 1,2 etc.

A:

I was able to resolve by adding an extra character after the $id1 like $id1:. 
Example:
id1=abc
id2=xyz
without the extra code $id11 was giving as abc1

