String
String
1. length ( ) – used to find length of any string . Its return type is integer . It counts space
also .
eg String s = “ carmel school “;
int l = s.length( );
output l =13.
2. charAt ( ) – used to extract a single character from a specified position . Its type is
character.
eg String s = “ carmel” ;
char c = s.charAt(3); output - m
char c = s.charAt(6); no output , run time error
eg String s = “ carmel” ;
String c = s.substring(0,3); output - car
String c = s.substring(4); output – el
String c = s.substring(4,8); no output , run time error
4. equals( ) – used to compare two string . Its return type is Boolean .It is case sensitive.
eg String s1 = “car” , s2 = “car” , s3=”CAR” ,s4 = “bus”;
boolean b1= s1.equals(s2) ; output – true
boolean b1= s1.equals(s3) ; output - false
boolean b1= s1.equals(s4) ; output – false
5. equalsIgnoreCase( ) – used to compare two string only. Its return type is Boolean .It is
not case sensitive.
6. toUpperCase( ) – used to convert letters of the string in upper case. Its type is
string.Numbers will be unchanged.
7. toLowerCase( ) – used to convert letters of the string in lower case. Its type is string.
Numbers will be unchanged.
12. trim ( ) –used to remove leading and trailing blank space from the string .Others blank
space in between the words will remain unchanged.
13. endsWith ( ) – used to check whether a given string ends with specified string or not.
It is of Boolean type .
14. startsWith ( ) – used to check whether a given string starts with specified string or
not. It is of Boolean type .