I wrote a method to remove comments from java code in order to compare two programs. There is a regular expression that can do this but I didn't know it at the time. This method does not ignore 'comment' strings inside quoted strings, as it should, but it was good enough for my purpose:
I'm a fan of using lexers for parsing text (using JFlex, for example), and I think this problem would be a perfect candidate for one. It'd also make a good introduction on how to create lexers since it's not a very involved problem. The result would be easier to maintain -I'd argue that the above code is not very maintainable by someone who didn't write it- and it would be much easier to extend (in case the underlying parsing becomes more complex, as -over time- is usually the case).