Java String Methods

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 15 Tutorials
Reference Index

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.

01

Full Tutorials

15 methods with examples.

02

Quick Reference

All methods by category.

03

Searchable

Filter by method name.

04

Immutable Strings

Methods return new text.

05

Beginner Tips

equals() vs == explained.

06

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.

💡
Beginner Tip

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 methods

Read characters by index and work with Unicode code points—including emoji and supplementary characters.

Comparison & Ordering

5 methods

Compare strings for equality, case rules, lexicographic order, and content match with StringBuilder.

Search & Match

2 methods

Check whether text includes a substring or ends with a suffix—common for validation and file extensions.

Build, Format & Encode

4 methods

Join 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) when variable may be null.
  • Pick the right searchcontains() 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 instanceformat() and copyValueOf() 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

GoalExample
Read a charactertext.charAt(0)
Compare contentstr1.equals(str2)
Find a substringurl.contains("/java")
Check file extensionfile.endsWith(".java")
Format outputString.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'}); // static

Conclusion

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

String methods are built-in operations on java.lang.String for reading characters, comparing text, searching substrings, joining strings, formatting output, and encoding bytes. You call most of them on a String variable: text.charAt(0), name.equals("Java").
Use dot notation on a String object: str.length(), str.contains("Java"), str.endsWith(".txt"). Static methods use the class name: String.format("Hi, %s", name) and String.copyValueOf(charArray).
equals() compares character content. == compares object references (same object in memory). Always use equals() to compare string text; use == only when you intentionally need reference identity.
contains() returns true or false when a substring is present. indexOf() returns the starting index or -1. Use contains() for yes/no checks; use indexOf() when you also need the position.
No. String objects cannot change after creation. Methods like concat() and toUpperCase() return new strings. For frequent edits, use StringBuilder or StringBuffer.
Start with charAt() to read characters, equals() for safe comparison, contains() for searching, and format() for readable output. Those four cover indexing, equality, search, and display—the most common everyday tasks.
Did you know?

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.

charAt() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

15 people found this page helpful