# Business Logic — Example.lines() [7 LOC]

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

## 1. Role

### Example.lines()

This method is a standalone demonstration of the `String.lines()` method introduced in Java 11 (JDK 11). The `String.lines()` API returns a `Stream<String>` where each element represents a line of text extracted from the original string by splitting at Unicode-aware line terminators (e.g., `
`, `\r
`, `\r`, ``, ` `, ` `). The method prepares a sample multi-line string, invokes `lines()` on it, collects the resulting stream into a `java.util.List`, and prints the list to standard output. It serves as an entry-point example method — invoked directly from `main()` — that showcases JDK 11's improved line-splitting capability compared to the older `String.split("\\R")` or manual `replaceAll` approaches. There are no conditional branches or business-domain logic; this is purely a technical demonstration method for library usage illustration.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["lines Entry"])
    STEP1["writeHeader: Print header separator and title"]
    STEP2["Declare str: multi-line sample string"]
    STEP3["str.lines collect Collectors.toList: Split by line terminators into List"]
    STEP4["System.out.println: Print result list to console"]
    STEP5(["lines Return"])

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

**Processing steps:**
1. **`writeHeader("String.lines()")`** — Invokes the private helper method to print a formatted header (separator line, title, separator line) to the console, identifying this demonstration section.
2. **String declaration** — A multi-line sample string `"Hello 
 World, I,m
biezhi."` is assigned to the local variable `str`. This string contains two line-feed characters (`
`), producing three logical lines.
3. **`str.lines().collect(Collectors.toList())`** — The `String.lines()` method is called on `str`, which splits the string by line terminators and returns a `Stream<String>`. The stream is collected into a `List<String>` via `Collectors.toList()`. The resulting list contains three elements: `"Hello "`, `" World, I,m"`, and `"biezhi."`.
4. **`System.out.println(...)`** — The resulting list is printed to standard output in the default `List.toString()` format, e.g., `[Hello ,  World, I,m, biezhi.]`.
5. **Return** — The method returns `void`; execution ends and control returns to the caller (`main()`).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates entirely on locally declared state. |

**Instance fields or external state read:**
| Source | Description |
|--------|-------------|
| `Example.writeHeader()` (private static helper) | Accesses the `String.repeat(int)` method (Java 11) to generate separator characters. |
| `java.lang.String.lines()` (JDK 11 API) | Standard library method that splits a string by Unicode line terminators. |
| `java.util.stream.Collectors` | Provides the `toList()` collector to materialize the stream into a `List`. |

## 4. CRUD Operations / Called Services

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

No database, entity, or service component operations are performed. This method is a pure demonstration utility with no persistent data interaction.

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `writeHeader` | Example | - | Calls `writeHeader(String)` in `Example` to print a formatted console header. |
| - | `String.lines` | JDK 11 API | - | Calls `String.lines()` — returns a `Stream<String>` of line fragments from the source string. |
| - | `Collectors.toList` | JDK 11 API | - | Collects the `Stream<String>` into a `List<String>`. |

## 5. Dependency Trace

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

No screen/batch entry points found within 8 hops. Direct callers found: 1 method.
Terminal operations from this method: `writeHeader` [-], `String.lines` [-], `Collectors.toList` [-]

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Utility: Example.main | `Example.main` -> `Example.lines` | `writeHeader` [-], `String.lines` [-], `Collectors.toList` [-] |

This method is called only from the `main()` method of the same `Example` class, which serves as the single entry point for running the demonstration.

## 6. Per-Branch Detail Blocks

**Block 1** — [EXEC] `(L96)`
Header printing step.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `writeHeader("String.lines()")` // Prints a formatted console header with separator lines using String.repeat() |

**Block 2** — [SET] `(L98)`
Sample multi-line string declaration.

| # | Type | Code |
|---|------|------|
| 1 | SET | `str = "Hello 
 World, I,m
biezhi."` // Local variable: multi-line string with two 
 line terminators producing three lines |

**Block 3** — [EXEC] `(L100)`
Line extraction and console output.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `str.lines()` // JDK 11 API: splits string by line terminators, returns Stream<String> |
| 2 | CALL | `.collect(Collectors.toList())` // Collects stream into List<String>, e.g. ["Hello ", " World, I,m", "biezhi."] |
| 3 | CALL | `System.out.println(...)` // Prints the resulting list to standard output |

**Block 4** — [RETURN] `(L102)`
Void return. No value is returned.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `return;` // void method, control returns to caller |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `String.lines()` | API | JDK 11 method — splits a string by Unicode line terminators and returns a `Stream<String>`. Replaces the older `split("\\R")` pattern. |
| `Collectors.toList()` | API | Java Stream API collector that materializes a `Stream<T>` into a `java.util.List<T>`. |
| `writeHeader()` | Method | Private static helper that prints a decorative console header (separator + title + separator) using `String.repeat()`. |
| `String.repeat(int)` | API | JDK 11 method — returns a new string composed of the original repeated the given number of times. |
| `Stream<String>` | API | Java Stream interface representing a sequence of String elements supporting sequential and parallel aggregate operations. |
| `Example` | Class | Demonstration class for showcasing Java 11 String enhancements: `repeat()`, `lines()`, `strip()`, `stripLeading()`, `stripTrailing()`, `isBlank()`. |
