---

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

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

## 1. Role

### Example.demonstrateStringLines()

This method demonstrates the `String.lines()` API introduced in JDK 11, which splits a multi-line string into a `Stream<String>` of its individual lines. The method serves as an educational demo that showcases how JDK 11's `String.lines()` method works with a string containing embedded newline characters (`
`). It prepares a human-readable display string by escaping the newline separators, prints a descriptive header via `writeHeader()`, and then iterates over each line produced by `String.lines()`, printing it to standard output. As a utility/demo method within a JDK 11 feature showcase library (the `io.github.biezhi.java11` project), it has no business transaction role — its purpose is purely demonstrative and educational.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["demonstrateStringLines()"])
    S1["Declare originalString = literal string with line breaks"]
    S2["Declare stringWithoutLineSeparators via replaceAll"]
    S3["Call writeHeader with description"]
    S4["Split string into lines and print each to stdout"]
    END_NODE(["Return void / End"])

    START --> S1 --> S2 --> S3 --> S4 --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | - |

This method takes no parameters. It operates entirely on locally-defined data.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `writeHeader` | - | - | Calls `writeHeader(String)` in `Example` to print a header line to stdout |

This method makes one internal method call:

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `writeHeader` | - | - | Writes a formatted header string to `System.out` to label the demo output section |

Note: No data access (CRUD) operations are performed. No database or entity interactions occur. The method only performs string manipulation and console output.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | N/A | (Not called by any production code — demo entry point) | (none) |

The only reference to this method in the codebase is a commented-out call at line 106 of the same file (`// demonstrateStringLines();`). This method is a standalone demo entry point, not invoked by any screen, batch, or business component.

## 6. Per-Branch Detail Blocks

**Block 1** — SET `(local variable declaration)` (L37)

> Declare the source string containing embedded newline characters.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String originalString = "Hello
World
123"` | Local variable holding a 3-line string separated by `
` characters |

**Block 2** — SET `(string transformation)` (L39)

> Transform the source string into a display-friendly version by escaping newline characters, so the header label shows literal `
` instead of actual line breaks.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String stringWithoutLineSeparators = originalString.replaceAll("\
", "\\\
")` | Replace literal `
` with escaped `\
` for display |

**Block 3** — CALL `(writeHeader)` (L41)

> Print a descriptive header to label the demo output. The header reads: `String.lines() on 'Hello
World
123'`.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `writeHeader("String.lines() on '" + stringWithoutLineSeparators + "'")` | Delegates to `Example.writeHeader()` to print a formatted header line |

**Block 4** — EXEC `(String.lines() + forEach)` (L43)

> Split the original multi-line string into a `Stream<String>` of individual lines using JDK 11's `String.lines()` method, then print each line to standard output.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `originalString.lines().forEach(System.out::println)` | JDK 11 `String.lines()` splits by line-terminators into a Stream; forEach prints each line |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `String.lines()` | API | JDK 11 method that returns a `Stream<String>` of lines from a string, split by line-terminator characters (LF, CR, CRLF) |
| `originalString` | Variable | The source string containing embedded newline characters (`Hello
World
123`) |
| `stringWithoutLineSeparators` | Variable | A display-friendly copy of `originalString` where newline characters are escaped to literal backslash-n for readable header output |
| `writeHeader` | Method | Internal utility method that prints a formatted header separator and title to `System.out` |
| `
` | Escape sequence | Line feed (newline) character — ASCII 10 |
| JDK 11 | Platform | Java Development Kit version 11 — the `String.lines()` method was introduced in this release |

---