0% found this document useful (0 votes)
6 views2 pages

String Class Notes

In Java, a String is an immutable object that represents a sequence of characters, created either by string literals or the new keyword. StringBuffer is a mutable object that is synchronized and thread-safe, while StringBuilder is also a mutable object but is non-synchronized and offers better performance. Both StringBuffer and StringBuilder are subclasses of the CharSequence interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

String Class Notes

In Java, a String is an immutable object that represents a sequence of characters, created either by string literals or the new keyword. StringBuffer is a mutable object that is synchronized and thread-safe, while StringBuilder is also a mutable object but is non-synchronized and offers better performance. Both StringBuffer and StringBuilder are subclasses of the CharSequence interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

STRING IN JAVA

 AN OBJECT THAT REPRESENTS SEQUENCE OF CHARACTER


VALUES.

 EXAMPLE.,STUDENT IS A STRING OF 7CHARACTERS.

 IN JAVA STRING IS AN IMMUTABLE OBJECT WHICH MEANS IT


IS CONSTANT AND CANT BE CHANGED ONCE IT HAS BEEN
CREATED. Strings are used for storing text.

HOW TO CREATE A STRING

1) BY STRING LITERAL
2) BY NEW KEYWORD.--String Buffer/String Builder

1)JAVA STRING LITERAL IS CREATED BY USING DOUBLE


QUOTES.

String obj = “College”;

2)USING NEW KEYWORD .

String objname = new String(“College”);

 STRING IS A CLASS SO WE CAN ABLE TO CREATE AN


[Link],

String objname = new String(“College”); THIS COLLEGE WILL STORE


IN OBJNAME.

BY STRING LITERAL --- WE DON’T USE NEW KEYWORD.


BY NEW KEYWORD. --- WE WILL USE NEW KEYWORD.

STRING BUFFER

 An object that represents sequence of char values.

 Eg., Student is a string of 7 charaters.


 In java stringbuffer is a mutable object
 The string buffer class is a child of charsequence interface.
 Stringbuffer is synchronised/thread safe.(ie., multiple threads
cannot access It simultaneously).

How to create a stringbuffer object?

We can create by using new keyword.

StringBuffer refname = new Stringbuffer(“Student”);

STRING BUILDER : efficiency wise it is faster

 THE STRING BUILDER CLASS IS A CHILD OF CHARSEQUENCE


INTERFACE.

 STRING BUILDER IS NON SYNCHRONIZED /Non THREAD SAFE


I.E., MULTIPLE THREADS CAN ACCESS IT SIMULTANEOUSLY.

 Efficiency wise even more faster one.

You might also like