Introduction
The string class is a fundamental class because it is very hard to write the code without it. You can even write main() method without using the String class.
A string is a sequence of characters, as shown below.
- String name = “Deepak”;
Above are the examples of reference types in Java. As we have learned the reference type is created using new keywords in Java but wait a second, in the example given above, we don’t have a new one in it. In Java, we can create a string by having two types, which are given below.
- String name = “Deepak”;
- String name = new String(“String”);
Both lines will give you a reference variable of type “name” pointing to the string object “Deepak”. Thus, we can say that the String class in Java is a special class and does not require new to be instantiated.
String concatenation
Combining two or more strings together is called string concatenation. Java does not provide lots of rules to learn about string concatenation but you have to know them well.
Join the conversation! Your thoughts help the community grow.