Tsallaka zuwa abun ciki
Justice Tech School

Strings

A String is an object. Use length(), charAt(), toUpperCase(), toLowerCase(), indexOf(), substring(), replace(), contains(), trim() and split(). Strings are immutable. Compare content with equals(), never with ==. Text blocks with """ hold several lines.

Example
String s = "Hello, Java";
System.out.println(s.length());
System.out.println(s.toUpperCase());
System.out.println(s.substring(7));
System.out.println(s.indexOf("Java"));
System.out.println(s.replace("Java", "World"));
System.out.println("a".equals("a"));
System.out.println(String.join("-", "x", "y", "z"));

Result

11
HELLO, JAVA
Java
7
Hello, World
true
x-y-z

Exercise

Compare two strings correctly.

if (a.(b)) {}

Quiz Test

How should you compare String contents?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.