Yandex

Java Advanced ConceptsJava Advanced Concepts3

Java String Methods Reference



charAt()
public char charAt(int index)
Returns the character at the specified index in the string.
codePointAt()
public int codePointAt(int index)
Returns the Unicode code point at the specified index.
codePointBefore()
public int codePointBefore(int index)
Returns the Unicode code point before the given index.
codePointCount()
public int codePointCount(int beginIndex, int endIndex)
Counts Unicode code points in the specified text range.
compareTo()
public int compareTo(String anotherString)
Compares two strings lexicographically.
compareToIgnoreCase()
public int compareToIgnoreCase(String str)
Compares two strings ignoring case differences.
concat()
public String concat(String str)
Concatenates the specified string to the end of this string.
contains()
public boolean contains(CharSequence s)
Checks if the string contains the specified sequence.
contentEquals()
public boolean contentEquals(CharSequence cs)
public boolean contentEquals(StringBuffer sb)
Compares this string to another sequence or buffer for content equality.
copyValueOf()
public static String copyValueOf(char[] data)
public static String copyValueOf(char[] data, int offset, int count)
Returns a string that contains characters from a character array.
endsWith()
public boolean endsWith(String suffix)
Checks if the string ends with the specified suffix.
equals()
public boolean equals(Object anObject)
Checks if this string is equal to another object.
equalsIgnoreCase()
public boolean equalsIgnoreCase(String anotherString)
Checks if this string is equal to another string, ignoring case.
format()
public static String format(Locale l, String format, Object... args)
public static String format(String format, Object... args)
Returns a formatted string using specified format string and arguments.
getBytes()
public byte[] getBytes()
public byte[] getBytes(Charset charset)
public void getBytes(int srcBegin, int srcEnd, byte[] dst, int dstBegin)
public byte[] getBytes(String charsetName)
Encodes this string into a byte array using specified charset or default.
getChars()
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Copies characters from the string into a destination array.
hashCode()
public int hashCode()
Returns the hash code of the string.
indexOf()
public int indexOf(int ch)
public int indexOf(int ch, int fromIndex)
public int indexOf(String str)
public int indexOf(String str, int fromIndex)
Finds the index of a character or substring in the string.
intern()
public String intern()
Returns the canonical representation of the string from the string pool.
isEmpty()
public boolean isEmpty()
Checks if the string is empty (length is 0).
join()
public static String join(CharSequence delimiter, CharSequence... elements)
public static String join(CharSequence delimiter, Iterable elements)
Joins multiple strings using the specified delimiter.
lastIndexOf()
public int lastIndexOf(int ch)
public int lastIndexOf(int ch, int fromIndex)
public int lastIndexOf(String str)
public int lastIndexOf(String str, int fromIndex)
Returns the last index of a character or substring.
length()
public int length()
Returns the length of the string.
matches()
public boolean matches(String regex)
Checks if the string matches a regular expression.
offsetByCodePoints()
public int offsetByCodePoints(int index, int codePointOffset)
Returns the index within the string after codePointOffset code points.
regionMatches()
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
public boolean regionMatches(int toffset, String other, int ooffset, int len)
Tests if two string regions match.
replace()
public String replace(char oldChar, char newChar)
public String replace(CharSequence target, CharSequence replacement)
Replaces all occurrences of one character or sequence with another.
replaceAll()
public String replaceAll(String regex, String replacement)
Replaces each substring that matches a regex with the replacement.
replaceFirst()
public String replaceFirst(String regex, String replacement)
Replaces the first substring matching regex with the replacement.
split()
public String[] split(String regex)
public String[] split(String regex, int limit)
Splits the string based on a regex delimiter.
startsWith()
public boolean startsWith(String prefix)
public boolean startsWith(String prefix, int toffset)
Checks if the string starts with the given prefix.
subSequence()
public CharSequence subSequence(int beginIndex, int endIndex)
Returns a character sequence between specified indexes.
substring()
public String substring(int beginIndex)
public String substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string.
toCharArray()
public char[] toCharArray()
Converts the string to a new character array.
toLowerCase()
public String toLowerCase()
public String toLowerCase(Locale locale)
Returns a lowercase version of the string.
toString()
public String toString()
Returns the string itself.
toUpperCase()
public String toUpperCase()
public String toUpperCase(Locale locale)
Returns an uppercase version of the string.
trim()
public String trim()
Removes leading and trailing whitespace from the string.
valueOf()
public static String valueOf(boolean b)
public static String valueOf(char c)
public static String valueOf(char[] data)
public static String valueOf(char[] data, int offset, int count)
public static String valueOf(double d)
public static String valueOf(float f)
public static String valueOf(int i)
public static String valueOf(long l)
public static String valueOf(Object obj)
Converts different types of data into their string representation.


Welcome to ProgramGuru

Sign up to start your journey with us

Support ProgramGuru.org

You can support this website with a contribution of your choice.

When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.

PayPal

UPI

PhonePe QR

MALLIKARJUNA M