What is String in java ?

By Admin on

String in javaJava String provides a lot of concepts that can be performed on a string such as compare, concat, equals, split, length, replace, compareTo, intern, substring etc.

In java, string is basically an object that represents sequence of char values.

An array of characters works same as java string. For example:

  1. char[] ch={'j','a','v','a','t','p','o','i','n','t'};  
  2. String s=new String(ch);  
  3. String s="javatpoint";  

The java.lang.String class implements Serializable, Comparable and CharSequence interfaces.

The java String is immutable i.e. it cannot be changed but a new instance is created. For mutable class, you can use StringBuffer and StringBuilder class.

We will discuss about immutable string later. Let's first understand what is string in java and how to create the string object.

SPIRO Google Plus