Loading topic
String never changes after it is created. Every method that looks like an edit hands back a new object and leaves the original alone. This chapter explains the working model behind that rule, why the language designers chose it, and the mistakes it causes in everyday code. Later chapters bu7 min readString objects are immutable, as covered in the previous chapter. You should also be able to compile and run a single-file program with a recent JDK. Here you will see why s += x inside a loop is slow, how to me7 min readString and the + operator work. You should also know the difference between objects and primitives. Any recent JDK runs the examples.6 min readStringBuilder and call append and toString, as covered in the previous chapter. It also assumes you know that String is immutable. Here you will learn the methods that edit text already in a builder, the index rules they follow, and the mistakes 6 min readStringBuilder and call toString(). If you can't yet, read the chapter on building strings with StringBuilder first. It also assumes you know that arrays have a fixed size once created. Here you learn the difference between how much text a builde7 min readStringBuilder and StringBuffer look almost the same. They have the same methods, the same constructors, and the same growth behavior. This chapter covers the one real difference, thread safety, and what that difference does and does not buy you. It assumes you can use StringBuilder with `appen7 min read\n escapes and + on every line. A text block is a string literal that spans several lines and keeps its layout. This chapter covers the syntax, the rules for the opening and closing delimiters, how quotes behave, and the errors people6 min read""" delimiters and understand that a text block is an ordinary String. Here you will learn the exact rule the compiler uses to decide which leading spaces are removed and which are kept. You need JDK 15 or later to run the exampl7 min readString literal handles \n, \t and \". It also assumes you have seen the text block syntax (""" delimiters) and how indentation is stripped, both covered in earlier chapters. You need JDK 15 or later to run the examples.7 min read"""), know how the closing delimiter controls indentation, and know the escapes \s and \<newline>. It also assumes you have used String.format or printf. You need JDK 15 or later. Every example here is a complete snippet you can paste into a7 min readStringBuilder, StringBuffer, String.join, String.format, formatted, and text blocks, and pick one for each task.7 min read