Please can someone tell me how can I check for junk characters/strings like [] (I could not paste from the notepad in java,both square brackets are joint and its one character). I need to run an if condition for all the occurrences of such characters. Is it possible? If yes what methods can I use to achieve this.
Those are not necessarily junk characters. Most of the times, they are simple line breaks (\n). Notepad can't handle those, because it expects the combination of carriage return and line break (\r\n). In those cases, you should replace \n with (or more accurately, with System.getProperty("line.separator")).
As Rob mentioned, its most likely that you are seeing end of line characters in your String. If you are ever not sure what you are dealing with, you can always call .getBytes() to get a closer look for non-displayable or special characters, however keep in mind the default encoding.
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, that will fit in a stocking