Skip to Content
100 Java Mistakes and How to Avoid Them
book

100 Java Mistakes and How to Avoid Them

by Tagir Valeev
May 2024
Intermediate to advanced content levelIntermediate to advanced
352 pages
10h 45m
English
Manning Publications
Content preview from 100 Java Mistakes and How to Avoid Them

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Complete Coding Interview Guide in Java

The Complete Coding Interview Guide in Java

Anghel Leonard
Java Coding Problems

Java Coding Problems

Anghel Leonard
Modern Java in Action

Modern Java in Action

Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft

Publisher Resources

ISBN: 9781633437968Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link