Computer Science, asked by vermaameesha, 1 year ago

what is String in Java

Answers

Answered by madeehaftm
2

String is a sequence of characters

In java, string is an immutable object which means it is constant and can cannot be changed once it has been created.


vermaameesha: Is it a data type
vermaameesha: ??
Hacket: String is not a primitive data type
vermaameesha: ok
Hacket: It is refrence data type like scanner
madeehaftm: okay thanks :)
Hacket: alws wlcm
Answered by Hacket
2

A string is a sequence of characters. In Java, a string is an object. We can create a string using two ways:

1. By String literal:

String s1= "hello";

2. By using new operator

String s2=new String("Hello");

If we are creating string object using a string literal, JVM will store it in the constant pool. String constant pool is a special memory storage of Heap memory.

Whenever we create String object using literal, JVM firstly checks the String constant pool. If the string is already available in the constant pool. It will create only reference to that string. If not then, String object will be created and stored in the string constant pool.

If we are creating String using the new operator, the String object is created in Heap memory.

I Hope it helps

Thanks for asking

Similar questions