# String

The string is a built-in CLASS available in Java but it is almost used as a data type.

**Simply says String is a collection of characters.**

Example: 
String Str = "My name is Mahadev Deshmukh";

Here,
String = class, Str = Referal which stores Object,  "Java Program" = Object and 
Double quotes are known as String Literals. 

There are two ways to create a String object:

a] By string literal
b] By new keyword

So where this string value will be stored?

1. If you write syntax as String str = "My name is Mahadev Deshmuk";
then it will save in the Pool area.
2. If you write syntax as String str = new string("My name is Mahadev Deshmukh");
then it will save in the heap area as NEW creates a new object and Object always stores in the heap area.

there is a third situation also explained in the below image:

![Interning-of-String-in-Java.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1627786749782/oo69SBthw.jpeg)


You can learn more about this concept from [here].(https://www.geeksforgeeks.org/interning-of-string/) 


**Now, Let's look at the different String writing methods.**

Constructors are methods or functions used for creating a string object and below are the 3 types of constructors:

1. String (char [ ])
An array of characters is taken and converted into a string.

2. Byte Array, String (byte [ ])
An array of bytes is taken and converted into a string.

3. String str1 = new String ("Java");
A string literal is taken in this method and a new string is created using this method.



**Important Note:**
In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable. Once a string object is created its data or state can't be changed but a new string object is created.

