Java - String String Basics

What is a String?

A sequence of zero or more characters is known as a string.

Java string is represented by an object of the java.lang.String class.

String class is immutable. The contents of a String object cannot be modified after it has been created.

StringBuilder and StringBuffer

The String class has two companion classes, java.lang.StringBuilder and java.lang.StringBuffer.

The companion classes are mutable.

For example, to accumulate a string value to create a longer string value, you should use StringBuilder or StringBuffer;

The following code creates a String object and output its value


public class Main {
  public static void main(String[] args) {
    String s = "";
    System.out.println(s);/* ww w  .  java 2s. c  om*/