Java String
In java, string is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
is same as:
Java String class provides a lot of methods to perform operations on string such as compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc.
The java.lang.String class implements Serializable, Comparable and CharSequence interfaces.
What is String in java
Generally, string is a sequence of characters. But in java, string is an object that represents a sequence of characters. The java.lang.String class is used to create string object.
How to create String object?
There are two ways to create String object:
1) String LiteralJava String literal is created by using double quotes. For Example: |
2) By new keyword
In such case, JVM will create a new string object in normal(non pool) heap memory and the literal "Welcome" will be placed in the string constant pool. The variable s will refer to the object in heap(non pool).
Java String Example
output:
java strings example
Sign up here with your email
ConversionConversion EmoticonEmoticon