s2 = s1.toLowerCase() | Converts the string to all lowercase |
s2 = s1.toUppercCase() | Converts the string to all Uppercase |
s2 = s1.replace( 'x', 'y') | Replaces all appearances of x with y |
s2 = s1.trim() | Removes white spaces at the beginning and end of the string |
s1.equals(s2) | Returns 'true' if s1 is equal to s2 |
s1. equalsIgnoreCase(s2) | Returns 'true' if s1 = s2, ignoring the case of characters |
s1.length() | Gives the length of s 1 |
s1.chartAt(n) | Gives nth character of s 1 |
s1.compareTo(s2) | Returns 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 |
s1.lastIndexOf(‘x’) | Gives the position of the last occurrence of 'x' in the string s1 |
s1.startsWith(“s2”) | Returns true if s1 begins with s2 |
s1.endsWith(“s2”) | Returns true if s1 ends with s2 |
![]() |
String Methods: |
You might also like:
Subject :
Java
0 comments:
Post a Comment