9 Library methods

This chapter covers

  • Problems with StringBuilder constructor invocation
  • Stream API misuse patterns
  • getClass() method pitfalls
  • String-to-boolean conversion problems
  • Common mistakes in date and time formatting
  • Non-atomic call sequences

In previous chapters, we discussed the pitfalls of using library methods related to numbers, strings, collections, and maps. These are most of the essential parts of the standard library; however, there are other library methods that could be misused but did not fit the previous chapters. We consider these in this chapter.

9.1 Mistake 82: Passing char to StringBuilder constructor

If you use StringBuilder, you can either provide the initial content or create it empty and append the initial ...

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.