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: 3This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Challenge
EasyInside 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
}
}