Inside the String

Learn to access the individual elements of a string.

Collection

A collection is a general term used to group multiple values into a single unit. We use collections all the time in the real world―a book is a collection of pages, a train is a collection of train cars, and a wardrobe is a collection of clothes.

String

A string is a collection of characters, mostly treated as a single unit. A string is used to store text values like a name, address, message, etc.

Initializing the string

The following program demonstrates the initialization of a string:

Press + to interact
class Test
{
public static void main(String[] args)
{
String string1 = "It is a string";
System.out.println(string1);
}
}

In line 5, we declare string using double quotes "".

Accessing the characters in a string

Java allows us to access individual ...

Access this course and 1400+ top-rated courses and projects.