Gary came and asked me why the text replacement fails when he was actually passing in the correct arguments and using correct version of JDK (
replaceAll appears since JDK 1.4). Here's how he wrote initially:
String name = "hello world";
name.replaceAll("hello", "world");
Obviously he didn't carefully read the API doc, which saying that the end result will be returned and no modification will be made to the object (in this case the object is String). So, the correct way to replace the string is:
name = name.replaceAll("hello", "world");
Controversially, people would just use the first approach to replace any characters in the String. I didn't manage to tell him what's wrong when he's describing his problem to me until I literally see the code. Since the method is a member method of class String (by which I mean it is not static), I think it should mutate the object's state instead. There's more about this API which confuse people and eventually produce subtle bugs in your programs, we'll discuss about that next time.
Read more about String.replaceAll API here.