String endsWith is used to check if a String ends with the given suffix.
1 |
public boolean endsWith(String suffix) |
String endsWith is used to check if a String ends with the given suffix.
1 |
public boolean endsWith(String suffix) |
String startsWith method is used to check if a String starts with a specified substring. Startswith method has 2 variations and we will see both these.
1 2 |
public boolean startsWith(String prefix) public boolean startsWith(String prefix,int toffset) |
String replace methods are used to replace a part of string with a new string. We have 4 variations for replace in String
1 2 3 4 |
String replace(char oldChar, char newChar) String replace(CharSequence target, CharSequence replacement) String replaceAll(String regex, String replacement) String replaceFirst(String regex, String replacement) |
String lastIndexOf returns the index of the last occurrence of the given String for specified conditions searching backward. String lastIndexOf method can be used with multiple types of parameters
String indexOf returns the index of the given String for specified conditions. String indexOf method can be used with multiple types of parameters as shown below
1 2 3 4 |
public int indexOf(int ch) public int indexOf(int ch,int fromIndex) public int indexOf(String str) public int indexOf(String str,int fromIndex) |
String toUpperCase method is used to converts all characters in a given string to upper case. String has 2 toUpperCase methods.
1 2 3 |
public String toUpperCase() public String toUpperCase(Locale locale) |
String toLowerCase method is used to converts all characters in a given string to lower case. String has 2 toLowerCase methods.
1 2 3 |
public String toLowerCase() public String toLowerCase(Locale locale) |
String substring method is used to get a part of String using the start and end index. String had 2 substring methods.
1 2 3 |
public String substring(int beginIndex) public String substring(int beginIndex,int endIndex) |
String length method in java is used to get the length of a given string. String length method example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package com.kscodes.sampleproject; public class StringLengthExample { public static void main(String[] args) { String testStr1 = "This is Test String for calculating length"; String testStr2 = "Another String"; System.out.println("The Length of testStr1 is ::" + testStr1.length()); System.out.println("The Length of testStr2 is ::" + testStr2.length()); } } |
1 2 |
The Length of testStr1 is ::42 The Length of testStr2 is ::14 |
String equals and equalsIgnoreCase are used for comparing 2 Strings in java.Both these methods works exactly similar except for equalsIgnoreCase compares String ignoring case consideration. example