Search⌘ K

Introduction to Strings

Explore the fundamentals of Java Strings, including how to declare them using literals and constructors. Understand the difference between String objects and literals, and learn about the string pool mechanism in heap memory to optimize string usage.

What is a string?

In programming, a data type used to represent a piece of text instead of a numerical value is called a string. Numbers and special characters, like space, can also be part of a string. In many languages, including Java, a string is enclosed in double quotes (""). The following are some valid strings:

  • "I love Java."
  • "I am 17 years old."
  • "12345"
  • "&*3223"

Strings in Java

As said above, strings are used to store text literals.

Declaring a string using

...