# Io / Github / Biezhi / Java11 / String

## Overview

This package is a small Java 11 showcase focused on the newer `String` APIs. It appears to exist as a teaching or demo module: each method isolates one language feature and prints a simple before/after example so engineers can see how the JDK 11 string helpers behave in practice.

The module is intentionally lightweight. There is a single `Example` class, no package-level dependencies, and no data model beyond local sample strings used to demonstrate `String.lines()`, `strip()`, `stripLeading()`, `stripTrailing()`, and `isBlank()`.

## Key Class

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

This is the only class in the package and acts as the runnable entry point for the demo. Its role is not to provide reusable library functionality; instead, it groups a set of static demonstration methods around the JDK 11 string additions.

#### Responsibilities

- Format section headers consistently for console output.
- Show how each String API behaves with a concrete sample input.
- Provide a `main` method that selects which demo to run.

#### Important methods

- [`writeHeader(final String headerText)`](src/main/java/io/github/biezhi/java11/string/Example.java:24)
  - Builds a visual console header using `"=".repeat(...)`.
  - Takes one parameter, the header text to display.
  - Returns nothing and prints three lines to standard output: a separator, the title, and the separator again.
  - This method is private and exists purely to keep the demo output readable.

- [`demonstrateStringLines()`](src/main/java/io/github/biezhi/java11/string/Example.java:36)
  - Demonstrates `String.lines()` on a multi-line string.
  - Uses a sample value of `"Hello
World
123"` and prints each line separately.
  - Before printing, it escapes newline characters in the header text so the header itself stays on one line.
  - Returns nothing.

- [`demonstrateStringStrip()`](src/main/java/io/github/biezhi/java11/string/Example.java:49)
  - Demonstrates `String.strip()`.
  - Uses a sample string with leading and trailing spaces: `"  biezhi.me  23333  "`.
  - Prints the trimmed result wrapped in quotes so the whitespace effect is visible.
  - Returns nothing.

- [`demonstrateStringStripLeading()`](src/main/java/io/github/biezhi/java11/string/Example.java:59)
  - Demonstrates `String.stripLeading()`.
  - Uses the same sample string as `strip()`.
  - Prints the result after removing only leading whitespace.
  - Returns nothing.

- [`demonstrateStringStripTrailing()`](src/main/java/io/github/biezhi/java11/string/Example.java:69)
  - Demonstrates `String.stripTrailing()`.
  - Uses the same sample string as the other strip demos.
  - Prints the result after removing only trailing whitespace.
  - Returns nothing.

- [`demonstrateStringIsBlank()`](src/main/java/io/github/biezhi/java11/string/Example.java:79)
  - Demonstrates `String.isBlank()` across several inputs.
  - Checks an empty string, the platform line separator, a tab, and a spaces-only string.
  - Prints the result for each case, with labels in Chinese and English to distinguish the examples.
  - Returns nothing.

- [`lines()`](src/main/java/io/github/biezhi/java11/string/Example.java:96)
  - A second `String.lines()` example that collects the lines into a `List` via `Collectors.toList()` and prints the result.
  - Uses the sample string `"Hello 
 World, I,m
biezhi."`.
  - Returns nothing.

- [`main(String[] args)`](src/main/java/io/github/biezhi/java11/string/Example.java:104)
  - Entry point for the demo class.
  - Most demo calls are commented out, and the active call is `lines()`.
  - As written, running the class prints the list representation of the sample lines.

## How It Works

The class follows a simple console-demo pattern:

1. A method builds a formatted header.
2. A demo method prepares one sample string.
3. The method prints the header and then prints the result of the JDK 11 API being shown.

For example, `lines()` calls `writeHeader("String.lines()")`, then creates a string with embedded line breaks, calls `str.lines()`, and finally prints the collected result. The other demo methods follow the same shape, but instead of streaming lines they print the transformed string directly.

### Flow of a typical demo

```mermaid
flowchart TD
DemoEntry["Demo method"] --> Header["writeHeader"]
DemoEntry --> Sample["Prepare sample String"]
Sample --> ApiCall["Call JDK 11 String API"]
ApiCall --> Output["Print result to console"]
```

The `writeHeader` helper is important because it keeps all demonstrations visually consistent. It uses `String.repeat(int)`, which is itself another JDK 11 API, so even the formatting logic reinforces the theme of the package.

## Data Model

There is no persistent data model in this module. The code uses only local `String` variables and, in one case, a `List<String>` produced by `Collectors.toList()` when demonstrating `String.lines()`.

The important inputs are all sample literals embedded in the code:

- Multiline strings for `lines()`
- Whitespace-padded strings for the `strip*` methods
- Blank and whitespace-only strings for `isBlank()`

## Dependencies and Integration

### In-module dependencies

- The demo methods all depend on [`writeHeader`](src/main/java/io/github/biezhi/java11/string/Example.java:24) for consistent console formatting.
- `lines()` depends on `java.util.stream.Collectors` to collect the stream of lines into a list.

### External APIs

This module is centered on Java 11 standard library features:

- `String.repeat(int)` in `writeHeader`
- `String.lines()` in `demonstrateStringLines()` and `lines()`
- `String.strip()`
- `String.stripLeading()`
- `String.stripTrailing()`
- `String.isBlank()`

There are no third-party dependencies and no integration points with other packages in the indexed code.

## Notes for Developers

- The class is written as a demo harness, not a reusable utility. If you add new behavior, keep the output-driven style consistent.
- Several demo methods are currently unused in `main`. To exercise them, uncomment the relevant calls or replace the active call in `main`.
- `writeHeader` intentionally uses `String.repeat(...)`; if you change it, you may remove one of the examples the module is meant to showcase.
- The `lines()` method prints a collected list, while `demonstrateStringLines()` prints each line individually. That difference is useful if you are comparing stream-based processing with direct iteration.
- `demonstrateStringIsBlank()` uses locale-specific labels in the output. Preserve that formatting if you want the demo output to stay aligned with the original examples.

## Relationship Diagram

```mermaid
flowchart TD
StringModule["io.github.biezhi.java11.string"] --> ExampleClass["Example"]
ExampleClass --> writeHeaderMethod["writeHeader"]
ExampleClass --> demonstrateStringLinesMethod["demonstrateStringLines"]
ExampleClass --> demonstrateStringStripMethod["demonstrateStringStrip"]
ExampleClass --> demonstrateStringStripLeadingMethod["demonstrateStringStripLeading"]
ExampleClass --> demonstrateStringStripTrailingMethod["demonstrateStringStripTrailing"]
ExampleClass --> demonstrateStringIsBlankMethod["demonstrateStringIsBlank"]
ExampleClass --> linesMethod["lines"]
ExampleClass --> mainMethod["main"]
```
