Strings in Java
Strings in Java
STRINGS IN JAVA
Strings-Introduction
In Java, string is basically an object that represents
sequence of char values. An array of characters works
same as Java string.
<String_Type> <string_variable> = "<sequence_of_string>";
2) String is slow and consumes more memory when we StringBuffer is fast and consumes less memory
concatenate too many strings because every time it creates new when we concatenate t strings.
instance.
3) String class overrides the equals() method of Object class. So StringBuffer class doesn't override the equals()
you can compare the contents of two strings by equals() method of Object class.
method.
4) String class is slower while performing concatenation StringBuffer class is faster while performing
operation. concatenation operation.
5) String class uses String constant pool. StringBuffer uses Heap memory