String: – String is one of the most important data type in java. This facility is not available in C or C++. String is a sequence of a character. User can use string as non-numeric type data. The string classes a number of method that allow us to accomplish to variety of string manipulation of task. Some common string method are as fallows –

Some Most Commonly Used String Methods

Method Call

Task Performed

S2=S1.toLowerCase; Converts the string S1 to all lowercase
S2=S1.toUppercCase; Converts the string S1 to all Uppercase
S2=S1.replace(‘X’,’Y’); Replace all appearances of X with Y
S2=S1.trim(); Remove white spaces at the beginning and end of the string S1
S1.equals(S2) Return ‘true’ if S1 is equal to S2
S1.equalsIgnorCase(S2) Return ‘true’ if S1=S2, ignoring the case of characters
S1.lenth() Gives the length of S1
S1.ChartAt(n) Gives nth character of S1
S1.compareTo(S2) Return negative if S1<S2, positive if S1>S2, and zero if S1 is equal S2
S1.concat(S2) Concatenates S1 and S2
S1.substring(n) Gives substring starting from nth character
S1.substring(n,m) Gives substring starting from nth character up to mth (not including mth)
String.ValueOf(P) Creates a string object of the parameter P (simple type or object)
P.toString() Creates a string representation of the object P
S1.indexOf(‘X’) Gives the position of the first occurrence of ‘X’ in the string S1
S1.indexOf(‘X’,n) Gives the position of ‘X’ that occurs after nth position in the string S1
String.ValueOf(Variable) Convert the parameter value to string representation