Thuta Learning
BasicProgrammingbeginner

Strings

Relax. We'll talk through this in plain words — no textbook voice.

In Java, String is an object that holds text. In apps that process text, String methods come in handy every single day. Usernames, emails, search keywords, messages, titles, content—all of it is a String.

java
public class Main {
  public static void main(String[] args) {
    String title = "Java Tutorial";
    String email = "student@example.com";

    System.out.println("Length: " + title.length());
    System.out.println(title.toUpperCase());
    System.out.println("Has @: " + email.contains("@"));
    System.out.println("Domain starts at index: " + email.indexOf("example"));
  }
}

length() gives you the character count. toUpperCase() converts text to uppercase. contains() checks whether a piece of text is present, returning true/false. indexOf() returns the index where a piece of text first appears.

You should see
Length: 13 JAVA TUTORIAL Has @: true Domain starts at index: 8

Real-world use

String methods are used in search boxes, login forms, formatting content titles, email checks, and cleaning up usernames.

Easy traps

  • Avoid comparing String values with ==. If you want to compare their content in Java, use equals().
Strings | Thuta Learning