Java String Methods
What You’ll Find Here
The java.lang.String class provides dozens of methods for reading characters, comparing text, searching substrings, joining strings, formatting output, and encoding bytes. This page is your central hub: browse every method in our tutorial series, jump to full guides with examples and output, and learn patterns that work in real Java programs.
Full Tutorials
15 methods with examples.
Quick Reference
All methods by category.
Searchable
Filter by method name.
Immutable Strings
Methods return new text.
Beginner Tips
equals() vs == explained.
Start Here
charAt() → equals().
Introduction
In Java, strings are objects of type String. You call methods with dot notation: text.charAt(0), name.equals("Java"), file.endsWith(".java"). A few helpers are static and live on the class itself: String.format(...) and String.copyValueOf(...).
Strings are immutable—once created, their characters cannot change. Methods like concat() and toUpperCase() return new String objects rather than modifying the original.
Compare string content with equals(), not ==. The == operator checks whether two variables point to the same object, not whether the text matches.
String Methods Index
Search by method name or browse by category. Cards marked Tutorial link to full guides with syntax, five examples, output, and FAQs.
Character & Unicode
4 methodsRead characters by index and work with Unicode code points—including emoji and supplementary characters.
Comparison & Ordering
5 methodsCompare strings for equality, case rules, lexicographic order, and content match with StringBuilder.
Search & Match
2 methodsCheck whether text includes a substring or ends with a suffix—common for validation and file extensions.
Build, Format & Encode
4 methodsJoin strings, copy from char arrays, format placeholders, and encode text as bytes for I/O.
🚀 Usage Tips
- Use equals() for text — never compare string content with
==unless you mean reference equality. - Null-safe equals — write
"expected".equals(variable)whenvariablemay benull. - Pick the right search —
contains()for presence,endsWith()for suffixes,indexOf()when you need the position. - Prefer UTF-8 — use
getBytes(StandardCharsets.UTF_8)instead of the no-arg form for portable encoding. - Static vs instance —
format()andcopyValueOf()are static; most other methods are called on a String variable. - Read the tutorial — each linked method page includes syntax, five examples, a quick reference table, and FAQs.
📝 How to Call a String Method
Most String methods follow this pattern:
stringReference.methodName(arguments)Common Patterns
| Goal | Example |
|---|---|
| Read a character | text.charAt(0) |
| Compare content | str1.equals(str2) |
| Find a substring | url.contains("/java") |
| Check file extension | file.endsWith(".java") |
| Format output | String.format("Hi, %s", name) |
Instance Methods vs Static Methods
Most String methods run on an existing string object. Static methods belong to the String class and do not require a particular string instance to start with.
String greeting = "Hello";
char first = greeting.charAt(0); // instance: read character
boolean match = greeting.equals("Hello"); // instance: compare content
String joined = greeting.concat(", Java!"); // instance: join text
String formatted = String.format("Count: %d", 42); // static: template
String fromArray = String.copyValueOf(new char[]{'J','a','v','a'}); // staticConclusion
Java String methods cover almost every text task you will encounter as a beginner—from reading characters and comparing passwords to formatting reports and encoding bytes for files. Use this index to find the right method quickly, then open the full tutorial for syntax, examples, and best practices.
Start with charAt() and equals() if you are new to Java strings, then explore contains() and format() for search and output.
❓ Frequently Asked Questions
Tip: Java strings are immutable—methods like concat() and toUpperCase() return a new String. Compare text with equals(), not ==. Call static helpers on the class: String.format(...) and String.copyValueOf(...).
Start Your First String Method Tutorial
Open the charAt() guide—syntax, five examples, and a quick reference cheat sheet.
15 people found this page helpful
