Professional Documents
Culture Documents
String Handling: Part-I
String Handling: Part-I
String Handling: Part-I
Part-I
Example:
1. String s1="javatpoint";
s1.length();
// 10 is the length of javatpoint string
2. “hello”.legnth();
// 5 is the length of hello string
Note :
length is a final variable applicable for arrays. With the help of length
variable, we can obtain the size of the array.
Example:
int[] array = new int[4];
array.length; // it returns the value as 4
M.Srilatha Assistant Professor CSE
1. concat() :
II. String Concatenation
This method concatenates one string to the end of another string. This
method returns a string
Syntax: String concat(String anostr)
Example:
String s = “vrsec";
s = s.concat("! welocmes.");
The value of s is “vrsec! Welcomes”.
2. + (string concatenation) operator:
Which concatenates two strings
Syntax: string1+string2;
Example:
1. String s="Sachin“;
S+ " Tendulkar“;
// returns “Sachin Tendulkar”
2. String s =“Hello”+2+2;
// returns “Hello22”
3. String s =“Hello”+(2+2);
// returns “Hello4”
M.Srilatha Assistant Professor CSE
III. String Conversion
• toString():
Object class contains toString() method.It means
toString() is efined in Java.lang.Object pacakge.
We can use toString() method to get string
representation of an object.
If we did not define toString() method in your
class then Object class toString() method is
invoked.
If we define toString() method then Overridden
toString() method will be called.
Constructor Description
System.out.println("Student class
Constructor");
}
}
M.Srilatha Assistant Professor CSE
Method Overriding
• When a method in a subclass has the same name,
same parameters or signature and same return
type(or sub-type) as a method in its super-class,
then the method in the subclass is said to override
the method in the super-class. Example:
Upcasting
When Parent class reference variable refers to Child class object, it is
known as Upcasting