---
title: "DD16 — Example.demonstrateStringStrip()"
layer: Utility
module: string
package: io.github.biezhi.java11.string
fqn: io.github.biezhi.java11.string.Example
floc: 6
---

# (DD16) Business Logic — Example.demonstrateStringStrip() [6 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.demonstrateStringStrip()

This method serves as a **JDK 11 feature demonstration** for the `String.strip()` method introduced in Java 11 (JEP 318). It exemplifies a utility-level showcase pattern commonly found in API feature reference repositories: the method creates a sample string containing leading and trailing whitespace characters, invokes `String.strip()` to remove them, and prints the result to standard output for visual confirmation.

`String.strip()` differs from `String.trim()` in that it removes Unicode whitespace characters (code points <= U+0020) rather than only ASCII space characters, making it the correct choice for modern internationalized applications. This method's role in the larger system is purely **educational and demonstrative** — it is not called by any production screen, batch, or service component. Instead, it is invoked manually (typically from `main` or a test harness) to validate that the JDK 11 API behaves as expected.

The method has **no conditional branches**, **no parameters**, and **no persistent state**. It follows a simple linear pattern: (1) define a sample input, (2) display a formatted header, (3) print the stripped result. It is part of a family of demonstration methods including `demonstrateStringStripLeading()`, `demonstrateStringStripTrailing()`, `demonstrateStringIsBlank()`, and `demonstrateStringLines()` that collectively showcase new `String` API additions in JDK 11.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
    START(["demonstrateStringStrip()"])
    START --> STR_ASSIGN["Declare and assign originalString = '  biezhi.me  23333  '"]
    STR_ASSIGN --> WRITE_HDR["Call writeHeader('String.strip() on ' + originalString)"]
    WRITE_HDR --> WRITE_HDR_IMPL["writeHeader: print header separator line"]
    WRITE_HDR_IMPL --> PRINT_HDR["writeHeader: print header text"]
    PRINT_HDR --> PRINT_SEPARATOR["writeHeader: print closing separator line"]
    PRINT_SEPARATOR --> PRINT_STR["System.out.println(originalString.strip())"]
    PRINT_STR --> END(["Return / Next"])
    WRITE_HDR_IMPL --> PRINT_HDR
```

The processing flow is strictly linear with no conditionals:

1. **Declare and assign** a `String` variable `originalString` with leading and trailing whitespace.
2. **Call `writeHeader`** to print a formatted header block to `System.out` (this internally uses `String.repeat()` to generate separator lines and prints the header text between them).
3. **Call `System.out.println`** with the result of `originalString.strip()`, which produces the whitespace-trimmed output.
4. **Return** (implicit `void` return).

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no parameters. It operates on hardcoded sample data. |

**Local Variables / Internal State:**

| # | Variable | Type | Business Description |
|---|----------|------|---------------------|
| 1 | `originalString` | `String` | Sample input string containing leading and trailing whitespace characters, used to demonstrate the `strip()` method's trimming behavior. |

## 4. CRUD Operations / Called Services

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

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| - | `Example.writeHeader` | - | - | Calls `writeHeader` private method in `Example` for formatted console output |
| - | `System.out.println` | - | - | Writes the stripped string result to standard output (console) |

**Analysis:** This method performs **no database or persistent storage operations**. It is a pure demonstration that prints to `System.out`. The `writeHeader` method it calls also operates entirely in-memory, using `String.repeat()` for formatting and `System.out` for output. There are no CRUD operations (Create, Read, Update, Delete) against any entity or table.

## 5. Dependency Trace

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Main (commented) | `Example.main(args)` -> `demonstrateStringStrip()` | (none — no persistence) |

**Notes:**

- The method is defined as `public static void demonstrateStringStrip()`, making it callable from any context.
- In the source code, calls to this method are currently **commented out** (lines 107–109), meaning it is not invoked during normal application startup or test execution.
- It is intended to be called from the class's `main(String[] args)` method as part of a JDK 11 feature showcase/demo run, not as part of any production screen, batch, or CBS workflow.
- There are **no callers in any production screen class** (`KKSV*`), batch class (`KKBV*`), or CBS class.

## 6. Per-Branch Detail Blocks

This method contains **no conditional branches** (no if/else, switch, loops, or try/catch). The entire body executes linearly.

**Block 1** — LINEAR EXECUTION (L49–L54)

> Declare sample string, print header, print stripped result.

| # | Type | Code |
|---|------|------|
| 1 | SET | `String originalString = "  biezhi.me  23333  "` | Sample string with leading/trailing whitespace |
| 2 | CALL | `writeHeader("String.strip() on '" + originalString + "'")` | Print formatted header block to console |
| 3 | CALL | `writeHeader(String headerText)` → internally: `final String headerSeparator = "=".repeat(headerText.length() + 4)` | Generate separator line using JDK 11 `String.repeat()` |
| 4 | EXEC | `System.out.println("
" + headerSeparator)` | Print opening separator to stdout |
| 5 | EXEC | `System.out.println(headerText)` | Print header text to stdout |
| 6 | EXEC | `System.out.println(headerSeparator)` | Print closing separator to stdout |
| 7 | EXEC | `System.out.println("'" + originalString.strip() + "'")` | Print stripped string result to stdout |
| 8 | RETURN | `void` (implicit) | Return to caller |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `String.strip()` | JDK 11 API | A method on `java.lang.String` that removes leading and trailing whitespace characters. Unlike `trim()`, it handles Unicode whitespace (code points <= U+0020), making it suitable for internationalized text. |
| `String.trim()` | JDK Legacy API | Removes only ASCII space characters (0x20) from leading and trailing positions. Superseded by `strip()` for general-purpose use. |
| `String.stripLeading()` | JDK 11 API | Removes only leading whitespace characters from a string. |
| `String.stripTrailing()` | JDK 11 API | Removes only trailing whitespace characters from a string. |
| `String.repeat(int)` | JDK 11 API | Returns a string consisting of the current string repeated a specified number of times. Used internally by `writeHeader()` to generate separator lines. |
| `writeHeader` | Utility Method | A private static method in `Example` that prints a formatted header block to console — a separator line, the header text, and a closing separator line. Used across all demo methods for consistent output formatting. |
| JDK 11 | Technology | Java Development Kit version 11 (released September 2018), which introduced `String.strip()`, `String.stripLeading()`, `String.stripTrailing()`, `String.repeat()`, and `String.lines()` via JEP 318 (String Templates precursor effort) and JEP 322 (Locale-sensitive String.split()). |
| JEP 318 | Specification | JEP — JEP (JDK Enhancement Proposal) 318: "String Templates" (preliminary) — the broader effort under which several new `String` methods were added in JDK 11, including `strip()` and `lines()`. |
| `originalString` | Variable | Sample input string in the demo, containing leading/trailing spaces around the domain `biezhi.me` and a numeric suffix `23333`. |
