[go: up one dir, main page]

0% found this document useful (0 votes)
137 views17 pages

String - Handling

String objects in Java are immutable and cannot be changed once created. The String, StringBuffer, and StringBuilder classes provide different ways to work with strings. String objects store an immutable sequence of characters, while StringBuffer and StringBuilder allow modification of strings after creation. Java also provides wrapper classes for primitive types like int and char to allow object-oriented handling of these types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views17 pages

String - Handling

String objects in Java are immutable and cannot be changed once created. The String, StringBuffer, and StringBuilder classes provide different ways to work with strings. String objects store an immutable sequence of characters, while StringBuffer and StringBuilder allow modification of strings after creation. Java also provides wrapper classes for primitive types like int and char to allow object-oriented handling of these types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

String Handling

String
• In Java a string is a sequence of characters. But, unlike some other languages
that implement strings as character arrays, Java implements strings as
objects of type String.

• String object, you are creating a string that cannot be changed. That is, once
a String object has been created,
you cannot change the characters that comprise that string.

• Each time you need an altered version of an existing string, a new String
object is created that contains the modifications. The original string is left
unchanged. This approach is used because fixed, immutable strings can be
implemented more efficiently than changeable ones.

• For those cases in which a modifiable string is desired,


Java provides two options: StringBuffer and StringBuilder. Both hold strings
that can be modified after they are created
• The java string
substring() method returns a part
of the string.
• We pass begin index and end index
number position in the java substring
method where start index is inclusive
and end index is exclusive. In other
words, start index starts from 0
whereas end index starts from 1.
• It is important to understand that the equals( ) method and the == operator
perform two different operations.
• equals( ) method compares the characters inside a String object. The == operator
compares two object references to see whether they refer to the same instance .
Java uses primitive types, such as int and char, for
performance reasons. These data types are not part of the
object hierarchy.
At times, you will need to create an object representation
for one of these primitive types.
To address this need, Java provides classes that correspond
to each of the primitive types.
In essence, these classes encapsulate, or wrap, the
primitive types within a class. Thus, they are commonly
referred to as type wrappers.
• Number has concrete subclasses that hold
explicit values of each primitive
numeric type: Double, Float, Byte, Short,
Integer, and Long.

You might also like