Chapter 10. Handling Common Data Formats
Most of programming is handling data in various formats. In this chapter, we will introduce Java’s support for handling two big classes of data—text and numbers.
The second half of the chapter will focus on handling date and time information. These APIs received a major update during Java 8, and we’ll discuss the modern APIs in detail along with some pertinent information about the older form, which you may still encounter. We encourage updating to the new APIs for dates and times whenever possible.
Before we get to those complexities, let’s talk about textual data and strings.
Text
We have already met Java’s strings on many occasions. They consist of
sequences of Unicode characters and are represented as instances of
the String class. Strings are one of the most common types of data
that Java programs process (a claim you can investigate for yourself by
using the jmap tool that we’ll meet in Appendix B).
In this section, we’ll meet the String class in some more depth and understand
why it is in a unique position within the Java language. Later in the section,
we’ll introduce regular expressions, a very common abstraction for searching
text for patterns (and a classic tool in the programmer’s arsenal, regardless of
language).
Special Syntax for Strings
The String class is handled in a special way by the Java language. This is because, despite not being a primitive type, strings are so common that it makes sense for Java to have syntax ...
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.
Read now
Unlock full access