Java String Method
The java String class provides serveral methods in string such as compare(), concat(), equals(), length(), replace(), compareTo(), substring(), and etc.
There are commonly used string methods in Java. They are
- String concat(String str): It concatenates str2 at the end of string str1.
- char charAt(int where): It returns the character at a specified location.
- boolean equals(Object str): It is used to compare two strings for equality.
- boolean equalsIgnore(String str): It is used to compare two strings for equality but it ignores case differences.
- indexOf(): It is used to searches for the first occurrence of a character value.
- lastIndexOf(): It is used to searches for the last occurrence of a character value.
- int compareTo(String str): It is used to compares the given string with the invoking string.
- length(): It is used to find the length of the string. It returns the count number of characters.
- capacity(): It is used to find the total allocated capacity of string.
- append(): It concatenates str2 at the end of string str1.
- delete(): It is used to delete a sequence of characters from the invoking object.
- reverse(): It returns the reverse object when it was invoked.
- replace(): It replaces one set of characters with another set of characters.
- substring(): It returns a portion of the StringBuffer.
- trim(): It is used to remove leading and trailing whitespace.
Example:
public class Stringmethod{
public static void main(String args[]){
String s1="Welcome";
s1=s1.concat(" to Onlinetpoint");
System.out.println(s1);
}
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com