Java_String_Methods_CheatSheet
Java_String_Methods_CheatSheet
length()
Example: str.length();
charAt(int index)
Example: str.charAt(0);
substring(int beginIndex)
Example: str.substring(2);
equals(String another)
Example: str1.equals(str2);
equalsIgnoreCase(String another)
Example: str1.equalsIgnoreCase(str2);
isEmpty()
Example: str.isEmpty();
isBlank()
trim()
Example: str.trim();
toLowerCase()
Example: str.toLowerCase();
toUpperCase()
Example: str.toUpperCase();
concat(String str)
Example: str.concat("World");
indexOf(String str)
Example: str.indexOf("a");
lastIndexOf(String str)
Example: str.lastIndexOf("a");
contains(CharSequence s)
Example: str.contains("text");
startsWith(String prefix)
Example: str.startsWith("He");
endsWith(String suffix)
Example: str.endsWith("ld");
matches(String regex)
Example: str.matches("\\d+");
strip()
stripLeading()
Example: str.stripLeading();
stripTrailing()
Example: str.stripTrailing();
split(String regex)
toCharArray()
valueOf(int i)
Example: String.valueOf(100);
compareTo(String another)
Example: str1.compareTo(str2);
intern()
Example: str.intern();
repeat(int count)