Module 2 - String
Module 2 - String
Gowri Prasood u
1
SENSE
VIT Chennai
2
String
Java charAt()
It returns the character at the specified index in a string.
• s1.indexOf('t', 8) returned the character ‘t’ index after the 8th index.
• s1.indexOf("on", 12) returned the index of the string “on” after the 12th index.
13 Java compareTo()
It compares two strings lexicographically (in the dictionary order).
It returns 0 if both the strings are the same, a positive value if the first string
comes after the second string and a negative value if the first string comes
before the second string in the dictionary order.
While comparing two strings, the Unicode values of their characters are
compared. The character having the lower Unicode value is smaller.
14 Java String equals()
The Java String class equals() method compares the two given strings based on the
content of the string. If any character is not matched, it returns false. If all characters are
matched, it returns true.
15 Java String equalsIgnoreCase()
The Java String class equalsIgnoreCase() method compares the two given strings on the
basis of the content of the string irrespective of the case (lower and upper) of the string.
16 Java String endsWith()
Method checks if this string ends with a given suffix. It returns true if this
string ends with the given suffix; else returns false.
17 Java String startsWith()
It returns a string with all the characters in uppercase. method checks if this
string starts with the given prefix. It returns true if this string starts with the
given prefix; else returns false.
18
19 Java StringBuffer Class
The insert() method inserts the given string with this string at the given position.
22 StringBuffer replace() Method
The replace() method replaces the given String from the specified beginIndex and
endIndex.
23 StringBuffer delete() Method
The delete() method of the StringBuffer class deletes the string from the specified
beginIndex to endIndex-1.
24 StringBuffer reverse() Method
The reverse() method of the StringBuilder class reverses the current string.
StringBuffer capacity() Method
25
The capacity() method of the StringBuffer class returns the current capacity of the buffer.
The default capacity of the buffer is 16.
If the number of characters increases from its current capacity, it increases the capacity by
(oldcapacity*2)+2.
26
27 Java Wrapper Classes
The wrapper class in Java provides the mechanism to convert primitive into object and
object into primitive.
28
For example, Integer is a predefined wrapper class, and its object
is used to store values of type int.
29 Creating Wrapper Class
30
The following methods are used to get the value associated with the corresponding
wrapper object
31 Java Autoboxing
Java can also automatically convert a primitive type into the corresponding wrapper class
object. This process is known as autoboxing.
32 Java unboxing
Unboxing is just the opposite of autoboxing. It is the process in which Java
automatically converts a wrapper class object into the corresponding
primitive type.
33
Java Program to convert all primitives into its corresponding
wrapper objects and vice-versa.
34
Thank you