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

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

## 1. Role

### Example.demonstrateStringLines()

This method provides a simple JDK 11 feature demonstration that converts a multi-line sample string into individual lines and prints each line to the console. From a business perspective, it acts as a showcase routine for validating how the platform handles line-separated text content, which is common in message bodies, descriptions, logs, and imported text payloads. The method first prepares a sample string, then creates a display-safe header representation by escaping newline characters, and finally streams the string by line to standard output. Its role in the larger system is not to perform domain CRUD or persistence work, but to illustrate a core language capability that other examples in the module can reuse as a reference pattern. The processing is linear and non-branching, so there are no alternative business routes or conditional service paths inside this method.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["demonstrateStringLines()"])
    INIT["Set originalString to sample multi-line text
Hello, World, 123"]
    CLEAN["Create display-safe string by replacing newline characters with escaped text"]
    CALL_HEADER["Call writeHeader with the formatted title"]
    STREAM["Invoke originalString.lines() to split the text into lines"]
    FOREACH["Iterate over each line using forEach(System.out::println)"]
    END_NODE(["Return / Next"])

    START --> INIT
    INIT --> CLEAN
    CLEAN --> CALL_HEADER
    CALL_HEADER --> STREAM
    STREAM --> FOREACH
    FOREACH --> END_NODE
```

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method accepts no input parameters. It uses only locally defined sample text and the `writeHeader` helper, so all behavior is deterministic and self-contained. |

External state read by the method: the static helper `writeHeader(...)` from the same class and `System.out` for console output.

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Example.writeHeader` | Example | - | Calls `writeHeader` in `Example` |

This method does not perform business CRUD against a database or service layer. Its only internal dependency is a utility-style header writer, followed by direct console printing of each line produced by `String.lines()`.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `writeHeader` | Example | - | Renders a descriptive section header before displaying the line-by-line output |
| R | `String.lines()` | JDK 11 String API | - | Reads the string content and exposes it as a stream of lines |
| R | `System.out::println` | Java standard output | - | Writes each extracted line to the console for demonstration purposes |

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Example (self-reference from `main` comment) | `Example.main` -> `Example.demonstrateStringLines` | `System.out::println [R] Console` |

The source scan found one direct reference in the same class via a commented invocation from `main`. No external screen, controller, batch, or CBS caller is present in the scanned source set. The method's execution chain is therefore self-contained and terminates in console output rather than a domain service endpoint.

## 6. Per-Branch Detail Blocks

**Block 1** — [SEQUENTIAL] `(method entry)` (L36)

> Initializes a fixed sample string for the JDK 11 line-splitting demonstration.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String originalString = "Hello
World
123";` |

**Block 2** — [SEQUENTIAL] `(prepare display string)` (L38)

> Converts newline characters into escaped text so the header can show the original content in a single line.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String stringWithoutLineSeparators = originalString.replaceAll("\
", "\\\
");` |
| 2 | EXEC | `originalString.replaceAll("\
", "\\\
")` |

**Block 3** — [SEQUENTIAL] `(render title)` (L40)

> Outputs a formatted section title describing the sample string being demonstrated.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `writeHeader("String.lines() on '" + stringWithoutLineSeparators + "'");` |

**Block 4** — [SEQUENTIAL] `(split and print lines)` (L42)

> Uses the JDK 11 `String.lines()` stream to enumerate every logical line and print it to standard output.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `originalString.lines()` |
| 2 | EXEC | `originalString.lines().forEach(System.out::println);` |
| 3 | EXEC | `System.out::println` |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `lines()` | Java API | JDK 11 `String` method that returns a stream of text lines split by line terminators. |
| `writeHeader` | Utility method | Helper used to print a formatted title or banner before example output. |
| `System.out` | Standard output | Console output channel used to display demonstration results. |
| `replaceAll` | Java API | Regex-based string replacement used here to make newline characters visible in the title text. |
| `originalString` | Local variable | Sample multi-line text used as the source for the line-by-line demonstration. |
| `stringWithoutLineSeparators` | Local variable | Presentation-only version of the sample string with newline markers escaped for display. |
| JDK 11 | Platform term | Java Development Kit version 11, which introduced `String.lines()` as a standard API. |
| Utility | Layer | A helper-style class focused on reusable demonstrations rather than domain CRUD or persistence. |
| `
` | Escape sequence | Newline marker used in string literals to represent line breaks. |
| `Hello
World
123` | Sample data | Fixed demonstration content containing three logical lines. |
