Java String & Character Methods Cheat Sheet
Important String Methods
• length() → Returns number of characters
• charAt(index) → Returns character at index
• substring(begin, end) → Extracts part of string
• equals(str) → Compares values (case-sensitive)
• equalsIgnoreCase(str) → Compares ignoring case
• compareTo(str) → Lexicographic comparison
• toLowerCase() / toUpperCase() → Change case
• trim() → Removes leading/trailing spaces
• indexOf(str) → First occurrence index
• lastIndexOf(str) → Last occurrence index
• contains(str) → Checks substring presence
• replace(old, new) → Replaces characters
• replaceAll(regex, repl) → Replace using regex
• split(regex) → Splits into array
• startsWith(prefix) → Checks starting text
• endsWith(suffix) → Checks ending text
• isEmpty() → Checks if string is empty
• valueOf(data) → Converts data to String
Important Character Methods (Character class)
• [Link](ch) → Checks if letter
• [Link](ch) → Checks if digit
• [Link](ch) → Checks if space
• [Link](ch) → Checks uppercase
• [Link](ch) → Checks lowercase
• [Link](ch) → Converts to uppercase
• [Link](ch) → Converts to lowercase
• [Link](ch) → Gets numeric value
Interview Tip:
Most commonly used methods in coding interviews: length(), charAt(), substring(), equals(),
indexOf(), split(), replace(), [Link](), [Link]().