# Io / Github / Biezhi / Java11 / String

## Overview

This package appears to be a small JDK 11 string-feature demo module. It centers on one `Example` class that prints console output showing how newer `String` APIs behave, including `repeat`, `lines`, `strip`, `stripLeading`, `stripTrailing`, and `isBlank`.

The module exists to make these APIs easy to observe from a running program rather than just read about them. It is intentionally simple: the code is organized as a set of focused demonstration methods plus a shared header-printing helper.

## Key Classes and Interfaces

### [Example](src/main/java/io/github/biezhi/java11/string/Example.java:16)

`Example` is the only class in this package and acts as the executable entry point for the string demonstrations. It is not a reusable library abstraction; instead, it is a teaching/demo class that prints examples of JDK 11 string behavior to standard output.

#### Role in the module

- Hosts the demonstrations for the newer `String` methods.
- Provides one shared helper, `writeHeader`, to make console output easier to read.
- Contains `main`, which selects which demonstration to run.

#### Important methods

- **[writeHeader(final String headerText)](src/main/java/io/github/biezhi/java11/string/Example.java:24)**
  - Purpose: prints a visual separator and title for a demo section.
  - Parameter: `headerText`, the title to display.
  - Return value: `void`.
  - Behavior: builds a divider line by repeating `=` with `String.repeat(int)`, using `headerText.length() + 4` to size the border. Then it prints a blank line, the border, the title, and the border again.
  - Why it matters: the helper makes each example self-describing in the console and also serves as a concrete example of `String.repeat()`.

- **[demonstrateStringLines()](src/main/java/io/github/biezhi/java11/string/Example.java:36)**
  - Purpose: demonstrates `String.lines()` on a multi-line string.
  - Parameters: none.
  - Return value: `void`.
  - Behavior: creates `"Hello
World
123"`, rewrites the newline characters for display, prints a header, then streams the lines and prints each one.
  - Why it matters: shows how `lines()` splits a string into line-delimited segments without manual parsing.

- **[demonstrateStringStrip()](src/main/java/io/github/biezhi/java11/string/Example.java:49)**
  - Purpose: demonstrates `String.strip()`.
  - Parameters: none.
  - Return value: `void`.
  - Behavior: prints the original string with surrounding spaces, then prints the stripped result wrapped in quotes.
  - Why it matters: highlights whitespace trimming using the JDK 11 Unicode-aware API.

- **[demonstrateStringStripLeading()](src/main/java/io/github/biezhi/java11/string/Example.java:59)**
  - Purpose: demonstrates `String.stripLeading()`.
  - Parameters: none.
  - Return value: `void`.
  - Behavior: prints a sample string and then prints the value after removing leading whitespace only.
  - Why it matters: distinguishes leading-only trimming from full trimming.

- **[demonstrateStringStripTrailing()](src/main/java/io/github/biezhi/java11/string/Example.java:69)**
  - Purpose: demonstrates `String.stripTrailing()`.
  - Parameters: none.
  - Return value: `void`.
  - Behavior: prints a sample string and then prints the value after removing trailing whitespace only.
  - Why it matters: shows the inverse of `stripLeading()`.

- **[demonstrateStringIsBlank()](src/main/java/io/github/biezhi/java11/string/Example.java:79)**
  - Purpose: demonstrates `String.isBlank()` with several inputs.
  - Parameters: none.
  - Return value: `void`.
  - Behavior: prints the results for an empty string, the platform line separator, a tab, and spaces. The labels include Chinese text describing each case.
  - Why it matters: shows that `isBlank()` treats whitespace-only strings as blank, not just zero-length strings.

- **[lines()](src/main/java/io/github/biezhi/java11/string/Example.java:96)**
  - Purpose: a second `String.lines()` example that collects the result into a list.
  - Parameters: none.
  - Return value: `void`.
  - Behavior: prints a header, defines a sample string with embedded newlines, and prints the result of `str.lines().collect(Collectors.toList())`.
  - Why it matters: demonstrates that `lines()` can be consumed as a stream and collected for later use.

- **[main(String[] args)](src/main/java/io/github/biezhi/java11/string/Example.java:104)**
  - Purpose: program entry point.
  - Parameters: `args`, the standard command-line argument array.
  - Return value: `void`.
  - Behavior: most demo calls are commented out. The active line calls `lines()`, so running this class currently exercises the list-collecting example only.
  - Why it matters: the file is meant to be edited or uncommented to run a specific demonstration.

## How It Works

The flow is straightforward:

1. `main` chooses a demo method to run.
2. The selected method calls `writeHeader` to print a consistent title block.
3. The method then prints the output of one JDK 11 string API in a small, focused example.
4. The program ends after the chosen demonstration completes.

A notable design choice is that each demo method is independent. There is no shared state, no input parsing, and no object model to maintain. That keeps the package useful as a reference when someone wants to see the behavior of a specific `String` API in isolation.

### Console output pattern

`writeHeader` establishes a repeatable output format:

- compute a separator length from the title length
- repeat `=` using `String.repeat(int)`
- print the separator, title, and separator again

This makes every demo section easy to scan in the terminal and also reinforces the feature being demonstrated.

### Example flow through `lines()`

For the active `main` path:

1. `main` calls `lines()`.
2. `lines()` prints a header using `writeHeader("String.lines()")`.
3. It defines a string containing newline characters.
4. It calls `str.lines()` to obtain a stream of line segments.
5. It collects the stream into a list with `Collectors.toList()` and prints the list.

### Relationship map

```mermaid
flowchart TD
  Main["Example.main"] --> Lines["lines()"]
  Main --> DemonstrateStringLines["demonstrateStringLines()"]
  Main --> DemonstrateStringStrip["demonstrateStringStrip()"]
  Main --> DemonstrateStringStripLeading["demonstrateStringStripLeading()"]
  Main --> DemonstrateStringStripTrailing["demonstrateStringStripTrailing()"]
  Main --> DemonstrateStringIsBlank["demonstrateStringIsBlank()"]
  Lines --> WriteHeader["writeHeader()"]
  DemonstrateStringLines --> WriteHeader
  DemonstrateStringStrip --> WriteHeader
  DemonstrateStringStripLeading --> WriteHeader
  DemonstrateStringStripTrailing --> WriteHeader
  DemonstrateStringIsBlank --> WriteHeader
```

## Data Model

There is no domain data model in this package. The examples work with plain `String` values and, in one case, a `List<String>` produced from `String.lines()`.

The main data shapes are:

- sample text with embedded line separators
- sample text with leading/trailing spaces
- boolean results from `isBlank()`
- a collected list of lines from `lines()`

## Dependencies and Integration

This module is self-contained and has no package-level dependencies recorded in the index.

### Standard library usage

The code depends only on core JDK APIs:

- `java.lang.String` methods introduced or highlighted in JDK 11
- `java.util.stream.Collectors` for collecting the stream returned by `lines()`
- `System.out` for console output

### Integration style

The package is intended to be run directly, not wired into a larger application flow. It integrates with the rest of the repository only as one example package among several JDK 11 feature demos.

## Notes for Developers

- The class is a demo harness, so clarity is more important than abstraction.
- `main` currently runs only `lines()`. If you want to see the other examples, uncomment the relevant method calls.
- `writeHeader` is private because it is only meant to support the demonstrations in this class.
- The examples intentionally use small, fixed strings so the behavior of each API is easy to verify by inspection.
- `demonstrateStringIsBlank()` uses the platform line separator via `System.getProperty("line.separator")`, which makes the example portable across operating systems.
- The method names are descriptive and correspond closely to the JDK 11 API being demonstrated, which makes the class easy to navigate as a reference.

## Related Source

- [src/main/java/io/github/biezhi/java11/string/Example.java](src/main/java/io/github/biezhi/java11/string/Example.java)
