String Class Vs String Buffer
String Class
- Immutable.
- Object length Fixed.
- Slow and consumes more memory during Concatenation.
- Every time it creates new instance.
- String constant pool. storage
- Overrides the equals() method of Object.
- Less functionality.
Example :
String str=new String ("easynotes");
str.concat("adda");
System.out.println( str );
Output
easynotes
String Buffer
- Mutable.
- Object length Grow able.
- Fast and consumes less memory during Concatenation.
- Heap Memory. storage
- Doesn't override the equals() method of Object.
- More functionality.
Example :
StringBuffer Sb= new StringBuffer ("easynotes");
Sb.append("adda");System.out.println( Sb );
Output
easynotes adda
0 Comments