6 Strings
This chapter covers
- Problems with characters that don’t fit the Java
char
type - Bugs caused by relying on the default system locale
- Discrepancies between format string and subsequent format arguments
- Accidental use of regular expressions
- Pitfalls associated with Java escape sequences
- Possible mistakes when using the
indexOf()
method
A variety of bugs may come up when using strings. Strings may appear deceivingly simple, but in fact, working with them correctly is quite difficult, as many common assumptions about them are incorrect.
6.1 Mistake 45: Assuming that char value is a character
Developers often assume the Java char
type corresponds to a single displayed character. They naturally expect the String.length()
method ...
Get 100 Java Mistakes and How to Avoid Them now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.