I started learning Java with The OU and really enjoying it but the assessments are driving me absolutely mad. I'm not considering myself an idiot but some of my brain cells are obviously not functioning properly because I constantly get stuck on the questions, which supposed to be easy...
Here's my problem:
I've been asked to write a method allowing replacement of all occurrences of old string within the source string with the new string (my args). I'm only allowed to use protocol from the StringBuilder class. My method works in the way that it finds the occurrences of the old string (using the required method indexOf(Str, int) within the for loop) but it doesn't replace any (using either combination of delete/insert or replace) and it throws index out of bounds exception at me. Reading through the StringBuilder API didn't make me any smarter and I've wasted lots of hours running around in circles.
My question is: how can I convince the StringBuilder object (source string converted to StringBuilder object) to replace old string with the new one?
Any hints please? I don't expect anyone to write the code for me just would like to know what I'm doing wrong.