Skip to content
Learn Netverks

Lesson

Step 9/36 25% through track

strings

Strings

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Strings: the syntax, APIs, and habits you need before advancing in Java.

Teams ship Strings on every Java codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Strings in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

String is Java's text type—immutable, UTF-16 internally. Concatenation with + is convenient; repeated concatenation in loops should use StringBuilder for performance.

Common operations

String s = "  Hello  ";
s.trim().toLowerCase();
s.length();
s.equals("hello");       // false — case sensitive
s.equalsIgnoreCase("hello");
s.contains("ell");
"Ada".substring(0, 2);   // "Ad"

Text blocks (Java 15+)

String json = """
    {"name": "Ada"}
    """;

Important interview questions and answers

  1. Q: Why are Strings immutable?
    A: Security (pooling, hashing), thread safety, and safe sharing across APIs.
  2. Q: String vs StringBuilder?
    A: String for fixed text; StringBuilder for efficient mutation in loops.

Self-check

  1. Which method compares String content?
  2. Why avoid + in a tight loop building large text?

Tip: Strings are immutable—methods like trim() return new instances; assign the result if you need the trimmed value.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • String immutable why?
  • StringBuilder when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump