Java String Functions': Visit at "JH X.KS'KK Ue%"
Java String Functions': Visit at "JH X.KS'KK Ue%"
Java String Functions': Visit at "JH X.KS'KK Ue%"
in
Strings - Collection of characters is called a string. String is a reference data type in java.
for eg.
String k="infotech";
2. charAt(int i) - this method of string class is used to extract a character from given index position of the
string.
for eg.
String k="infotech";
3. concat(String m) - this method of string class is used to concat a string into another string.
for eg.
String k="infotech";
String m="computer";
for eg.
String k="infotech";
String m="computer";
4. equals(String str) - this method of string class is used to compare two strings for thier equality.
for eg.
String k="infotech";
String m="infotech";
sout(k.equals(m)); - it will print true bcoz both of the strings are same
5. indexOf(char ch) - this method of string class is used to find position of first occurence of the given
character in string.
for eg.
String k="infotech";
6. equalsIgnoreCase(String str) - this method of string class is same as equals but it compares two string for
for eg.
String k="infotech";
String m="INFOTECH";
sout(k.equals(m)); - will print false bcoz both strings are not same
7. lastIndexOf(char ch) - this function of string class is same as IndexOf function but it will find the position
for eg.
8. startsWith(String str) - this function is used to find whether the string starts with the given string or not
for eg.
for eg.
String k="iNfOteCh";
12. trim() - will remove blank spaces from both sides of string.
for eg.
13. replace(char oldchar, char newchar) - this function will replace the given old character in string with
for eg.
INFOTECH Computer Education, Kishangarh (Raj) 9829171122 Page 4
visit @ http://www.infotechcomputer.in
String k="infotech";
14. substring(int begin,int end) - this funtion is used to extract a part of string from it.
for eg.
String k="infotech";
NOTE - index starts with 0 and 6th character will not print