Java String Methods Summary
Length & Indexing Methods:
- length(): Get the length of the string.
- charAt(): Access character at specific index.
- indexOf(): Find the first occurrence of a character or substring.
- lastIndexOf(): Find the last occurrence.
Comparison Methods:
- equals(): Check if two strings are exactly equal.
- equalsIgnoreCase(): Check if equal ignoring case.
- compareTo(): Compare strings lexicographically.
- startsWith(): Check if string starts with prefix.
- endsWith(): Check if string ends with suffix.
- contains(): Check if substring exists.
Transformation Methods:
- toUpperCase(): Convert to uppercase.
- toLowerCase(): Convert to lowercase.
- trim(): Remove leading/trailing spaces.
- replace(): Replace characters or substrings.
- substring(): Extract a portion of the string.
- format(): Format strings using placeholders.
Splitting & Checking Methods:
- split(): Split into parts by a regex.
- isEmpty(): Check if the string is empty.
Conversion Method:
- valueOf(): Convert other data types into strings.