Update qhelp

This commit is contained in:
Owen Mansel-Chan
2025-03-25 11:41:59 +00:00
parent 441c79ebdf
commit fea3d10b97

View File

@@ -1,14 +1,14 @@
# Use of `String#replaceAll` with a first argument which is not a regular expression
Using `String.replaceAll` is less performant than `String.replace` when the first argument is not a regular expression.
Using `String#replaceAll` is less performant than `String#replace` when the first argument is not a regular expression.
## Overview
The underlying implementation of `String.replaceAll` uses `Pattern.compile` and expects a regular expression as its first argument. However in cases where the argument could be represented by just a plain `String` that does not represent an interesting regular expression, a call to `String.replace` may be more performant as it does not need to compile the regular expression.
The underlying implementation of `String#replaceAll` uses `Pattern#compile` and expects a regular expression as its first argument. However in cases where the argument could be represented by just a plain `String` that does not represent an interesting regular expression, a call to `String#replace` may be more performant as it does not need to compile the regular expression.
## Recommendation
Use `String.replace` instead where a `replaceAll` call uses a trivial string as its first argument.
Use `String#replace` instead where a `replaceAll` call uses a trivial string as its first argument.
## Example
@@ -25,4 +25,4 @@ public class Test {
## References
- [String.replaceAll](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/String.html#replaceAll(java.lang.String,java.lang.String))
- Java SE Documentation: [String.replaceAll](https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/lang/String.html#replaceAll(java.lang.String,java.lang.String)).