Ch 11 · Strings — Working with Text · Java

Topic 11 of 13 in Java — Complete Tutorial (Beginner) — 2 lessons.

String Basics & Methods

A String holds text — names, messages, anything human-readable. Strings come with many built-in methods to inspect and transform text, which you call with a dot. A key rule: Strings are immutable, meaning a method like toUpperCase() does not change the original — it returns a brand-new String. To keep the change, store it in a variable. Get the number of characters with .length() (with brackets, unlike arrays).

Comparing Strings & Formatting

To compare two Strings for equal text, always use .equals(...), never ==. The == operator checks whether they are the exact same object in memory, which is usually false even when the text matches — a classic beginner bug. For building formatted text, String.format(...) and printf use placeholders like %d (whole number), %.2f (decimal to 2 places), and %s (string).

All topics in Java Beginner

  1. Introduction to Programming & Java
  2. Your First Java Program
  3. Variables — Your Data Containers
  4. Data Types — Kinds of Values
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Methods
  9. Arrays & Lists
  10. Objects & Classes
  11. Strings — Working with Text
  12. Exception Handling
  13. Mini-Projects & Practice