Menu
Coddy logo textTech

String

Lesson 3 of 16 in Coddy's Strings and Arrays in Java course.

Strings are used for storing text.

A String variable contains a collection of characters surrounded by double quotes:

String name = "Bob";

As you probably understood, a string is a non-primitive type and as such, it has its own methods (functions)!

The first we will meet is length(), which returns the length of the string,

String name = "Bob";
System.out.println(name.length());  // Outputs: 3
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

challenge icon

Challenge

Easy

Inside the main funciton:

1. Initialize a variable named car that holds the string "Volvo".

2. Output the length of the variable car, using the method length().

Try it yourself

class Main {
    public static void main(String[] args) {
        // Write code here
    }
}

All lessons in Strings and Arrays in Java