---
# (DD12) Business Logic — Example.demonstrateStringLines() [9 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.string.Example` |
| Layer | Utility (Inferred from package path: `io.github.biezhi.java11.string`) |
| Module | `string` (Package: `io.github.biezhi.java11.string`) |

## 1. Role

### Example.demonstrateStringLines()

This method is a **JDK 11 feature demonstration** that showcases the `String.lines()` API introduced in Java 11 (JEP 328). It performs a self-contained demonstration: it creates a multi-line string literal containing three lines ("Hello", "World", "123" separated by newline characters), then uses `String.lines()` to produce a `Stream<String>` of individual line elements, and prints each element to standard output. The method also preprocesses the string to escape literal `
` sequences (converting them to a visible double-backslash form) so the header line can display the original string in a human-readable, compact form. Its design pattern is a **straight-through procedural demonstration** — there are no conditional branches, no service delegation, and no external state reads. It is an isolated, static utility called by no other method in the codebase (the only reference on line 106 is commented out). Its role in the larger system is purely **educational/scaffold**: it belongs to a collection of small `demonstrate*` methods that each illustrate a specific JDK 11 String API addition (`String.repeat()`, `String.lines()`, `String.strip()`, `String.stripLeading()`, `String.stripTrailing()`).

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["demonstrateStringLines()"])
    STEP1["Initialize originalString = \"Hello\
World\
123\""]
    STEP2["Replace literal \
 with \\\
 for display"]
    STEP3["CALL writeHeader(\"String.lines() on ...\")"]
    STEP4["CALL originalString.lines().forEach(System.out::println)"]
    END_NODE(["Return / Next (void)"])

    START --> STEP1 --> STEP2 --> STEP3 --> STEP4 --> END_NODE
```

**Description of processing flow:**

1. **L37** — Initialize a multi-line `String` literal containing three text lines separated by newline (`
`) characters.
2. **L39** — Apply a regex-based `replaceAll()` on the original string, substituting every literal `
` escape with a double-backslash `\
` so the resulting display string renders the line breaks visibly rather than as actual newlines.
3. **L41** — Delegate to `writeHeader(...)` to print a formatted header line to standard output.
4. **L43** — Invoke the JDK 11 `String.lines()` method on the original string to obtain a `Stream<String>`, then chain `forEach()` with `System.out::println` to print each line individually.
5. **Return** — Method returns `void`; execution completes.

**No conditional branches, no loops (other than the implicit `forEach` iteration), no external service calls.**

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none — static method, no parameters) | - | - |

**Fields/External State Read:**
- None — this method is fully self-contained and reads no instance fields, static fields, or external dependencies.

## 4. CRUD Operations / Called Services

### Pre-computed evidence from code analysis graph:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Example.writeHeader` | Example | - | Prints a formatted header to stdout |
| - | `System.out.println` | java.io | - | Writes each line of the split output to the console |

**Analysis:** This method makes no database or service-layer calls. Both called methods (`writeHeader` and `System.out::println`) are console-output utilities. There are **zero** C/R/U/D operations.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `writeHeader` | Example | - | Console output — prints a header banner describing the current demonstration |
| - | `System.out::println` | java.io | - | Console output — prints each line element from the `String.lines()` stream |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | (none — only reference is commented out) | `Example.demonstrateStringLines()` [L106, commented out] | N/A |

**Analysis:** This method is **never invoked** in the live codebase. The sole reference to it on line 106 is commented out (`//        demonstrateStringLines();`). It is a standalone demonstration utility called manually by a developer or test harness, not by any screen, batch, or CBS layer.

## 6. Per-Branch Detail Blocks

This method has no conditional branches, switch statements, or loops. The entire method is a single linear block.

**Block 1** — [LINEAR / PROCEDURAL] `(no condition)` (L36–44)

> Initializes a multi-line string, escapes newlines for display, prints a header, then splits and prints each line.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String originalString = "Hello
World
123"` — Initializes a multi-line string literal with three newline-separated lines [L37] |
| 2 | SET | `String stringWithoutLineSeparators = originalString.replaceAll("\
", "\\\
")` — Replaces literal `
` escape sequences with `\
` (double-backslash-n) for human-readable display output [L39] |
| 3 | CALL | `writeHeader("String.lines() on '" + stringWithoutLineSeparators + "'")` — Delegates to `Example.writeHeader()` to print a formatted demo header to stdout [L41] |
| 4 | CALL | `originalString.lines().forEach(System.out::println)` — JDK 11 `String.lines()` splits the multi-line string into a `Stream<String>` of individual lines; `forEach` prints each line [L43] |
| 5 | RETURN | `void` — Method returns; no value to propagate [L44] |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `String.lines()` | JDK API | Java 11 method (JEP 328) that returns a `Stream<String>` of lines extracted from a multi-line string, splitting on line-terminator characters (`
`, `\r`, `\r
`) |
| `String.repeat(int)` | JDK API | Java 11 method that returns a new string consisting of the original string concatenated with itself a specified number of times |
| `String.strip()` | JDK API | Java 11 method that removes leading and trailing whitespace (Unicode-aware, unlike `trim()` which only removes ASCII <= 0x20) |
| `String.stripLeading()` | JDK API | Java 11 method that removes leading whitespace from a string |
| `String.stripTrailing()` | JDK API | Java 11 method that removes trailing whitespace from a string |
| `demonstrate*` | Method pattern | Naming convention used in this class for self-contained example methods that showcase individual JDK 11 String API additions |
| JEP 328 | Specification | JDK Enhancement Proposal that introduced `String.lines()` and `String.repeat()` in Java 11 |
| `writeHeader()` | Utility method | Static method in `Example` that prints a formatted header/banner line to standard output |
