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

| Field | Value |
|-------|-------|
| Fully Qualified Name | `io.github.biezhi.java11.string.Example` |
| Layer | Utility (Common Component) |
| Module | `string` (Package: `io.github.biezhi.java11.string`) |

## 1. Role

### Example.demonstrateStringLines()

This method demonstrates the `String.lines()` method introduced in JDK 11, which returns a `Stream<String>` of the lines contained in a string, separated by line breaks. It serves as a showcase utility within a collection of JDK 11 feature demonstrations, illustrating how multi-line text can be processed line-by-line using Java Streams. The method constructs a sample multi-line string ("Hello
World
123"), computes an escaped version for display purposes, prints a header label via `writeHeader()`, and finally iterates over each line produced by `String.lines()` to print them to standard output. Its role in the larger system is that of a self-contained example runnable — it can be invoked directly to verify JDK 11 string-processing behavior and is not part of any business workflow or data pipeline.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["demonstrateStringLines"])
    STEP1["Initialize originalString with text containing line breaks"]
    STEP2["Compute stringWithoutLineSeparators by replacing newlines"]
    STEP3["Call writeHeader with formatted label string"]
    STEP4["Stream originalString.lines() and print each line"]
    END_NODE(["Return void"])

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

1. **Initialize originalString** — Assigns the literal `"Hello
World
123"` (three lines separated by `
` newline characters) to a local variable.
2. **Compute stringWithoutLineSeparators** — Applies `replaceAll()` to replace each literal `
` character with the escaped representation `
` (backslash-n) for display labeling purposes.
3. **Call writeHeader** — Constructs a label string by concatenating `"String.lines() on '"`, the escaped string, and `"'"`, then passes it to `writeHeader()` to print a formatted section header to standard output.
4. **Stream lines** — Invokes `String.lines()` (JDK 11+) on `originalString`, producing a `Stream<String>` of three elements (`"Hello"`, `"World"`, `"123"`), and forEach-prints each element to `System.out`.
5. **Return void** — Method completes with no return value.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates entirely on locally constructed data. |
| - | `originalString` (local) | `String` | A sample multi-line string literal `"Hello
World
123"` used to demonstrate line-splitting behavior. |
| - | `stringWithoutLineSeparators` (local) | `String` | An escaped version of `originalString` with newline characters replaced by their literal `
` representation, used only for the header label. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `writeHeader` | Example | - | Calls `writeHeader` in `Example` to print a formatted header to stdout |
| - | `String.lines()` | JDK 11 API | - | Invokes `lines()` on String to produce a Stream of line substrings |
| - | `System.out::println` | Java IO | - | Writes each line to standard output |

All operations are utility-level method calls with no database or persistence interactions. This method does not perform any Create/Read/Update/Delete operations on enterprise data.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | `Example.demonstrateAll` (commented out, line 106) | `Example.demonstrateAll` -> `Example.demonstrateStringLines` | `writeHeader [EXEC] stdout` |

The only known reference to this method is a commented-out call on line 106 within the same `Example` class (`// demonstrateStringLines()`). It is not invoked by any active screen, batch, or controller in the codebase. The method is designed as a standalone example demo.

## 6. Per-Branch Detail Blocks

**Block 1** — [SET] `(initialization)` (L37)

> Assigns a multi-line string literal to the local variable `originalString`.

| # | Type | Code |
|---|------|------|
| 1 | SET | `originalString = "Hello
World
123"` // Literal string with two newline separators producing 3 lines |

**Block 2** — [SET] `(replaceAll transformation)` (L39)

> Computes an escaped version of the string where newline characters are replaced with their literal backslash-n representation, for use in the header label.

| # | Type | Code |
|---|------|------|
| 1 | SET | `stringWithoutLineSeparators = originalString.replaceAll("\
", "\\\
")` // Replaces newline chars with escaped 
 for display |

**Block 3** — [CALL] `(writeHeader output)` (L41)

> Constructs a formatted header label string by concatenating `"String.lines() on '"`, the escaped string value, and `"'"`, then writes it to standard output via `writeHeader`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `writeHeader("String.lines() on '" + stringWithoutLineSeparators + "'")` // Prints section header to stdout |

**Block 4** — [EXEC] `(lines() stream forEach)` (L43)

> Invokes the JDK 11 `String.lines()` method on `originalString`, which splits the string at line boundaries and returns a `Stream<String>`. Each line element is then printed to standard output via a method reference to `System.out.println`.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `originalString.lines().forEach(System.out::println)` // JDK 11: streams each line to stdout |

There are no conditional branches, loops (outside the implicit stream iteration), switch statements, or try-catch blocks in this method. The control flow is strictly sequential.

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `String.lines()` | JDK 11 API | A method on `java.lang.String` that returns a `Stream<String>` of lines from the string, split by line-break characters (`
`, `\r`, `\r
`). Part of the JDK 11 String enhancements. |
| `String.replaceAll` | JDK API | Replaces each substring of the string that matches the given regular expression with the given replacement. In this method, used to escape newline characters for display. |
| `forEach` | JDK Stream API | Terminal operation on a Stream that performs an action for each element. Here, invokes `System.out::println` for each line. |
| `System.out::println` | Java IO | Method reference to `PrintStream.println`, which writes a line to standard output. |
| `writeHeader` | Example Utility | Internal helper method in `Example` that prints a formatted section header (with line decorations) to stdout, used across all JDK 11 demos. |
| JDK 11 | Platform | Java Development Kit version 11 (released September 2018, LTS), source of the `String.lines()` enhancement. |
