String Data Type in Java

String Data Type in Java

Strings in Java:

It comes to programming Java strings are the one of the important concept.

String are nothing but sequence of characters.Java provides the String class to process Strings. so, Strings are Objects.Strings are available in the package java.lang.package

Basic syntax to create Strings:

String str = “Welcome to Strings Concept.”
String str = new String(“Welcome to Strings Concept.”)

Note: There we can use any one of the basic syntax to generate Strings., in the further lines we are going to discuss difference between each syntax. and the letter ‘S’ in String class must be capital as we know every class first letter is Capital letter.
Java supports two types of Strings.
  1. Immutable Strings
  2. Mutable Strings

Immutable Strings:

Strings are immutable i.e. Once the String is created and initialized the value, whose values cannot be changed. syntax to create immutable Strings are

  1. String str1= “Java”;
    String str2 = “Become A Geek”
  2. String str1 = new String (“Java”); String str2 = new String(“Become A Geek”);
Rules of the immutable String
  • In order to compare the contents of 2 Strings the inbuilt method equals can be used.
  • To compare the address of the String We follow “==” operator.
  • Strings which are declared without the new operator then the memory of the String is occupied in the Constat pool.
  • Strings which are declared with the new Operator will occupy the memory in the Non constant pool.


Leave a Reply

Your email address will not be published. Required fields are marked *