🔤Java Strings Programs
String questions open almost every Java interview because they test loops, character handling and the difference between String and StringBuilder in one go. Start with the classics below, then work through the full list grouped by difficulty.53 programs · each with full code, output and a step-by-step explanation
Most Asked in Interviews
Converts a sentence to title case, upper-casing each word's first letter and tidying extra spaces.
View Program →Check whether a string reads the same forwards and backwards.
View Program →Determines whether a string is made up entirely of letters.
View Program →Determines whether a string is made up entirely of digits.
View Program →Compares two strings and reports their lexicographic order.
View Program →Splits a string into a char array with toCharArray and shows the array is an independent copy.
View Program →Converts every letter in a string to lowercase.
View Program →Converts every letter in a string to uppercase.
View Program →Counts how many vowels and consonants a string contains, skipping spaces and punctuation.
View Program →Counts how many consonants appear in a string.
View Program →Counts how many digit characters appear in a string.
View Program →Counts how many space characters appear in a string.
View Program →Counts how many special characters appear in a string.
View Program →Counts the total number of characters in a string without using length().
View Program →Counts how many vowels appear in a string.
View Program →Counts how many words a sentence contains.
View Program →Finds the longest word in a sentence.
View Program →Finds the shortest word in a sentence.
View Program →Removes every digit character from a string.
View Program →Removes every space character from a string.
View Program →Removes every special character from a string, keeping letters, digits, and spaces.
View Program →Removes every vowel from a string.
View Program →Replaces every occurrence of one character with another.
View Program →Replaces every occurrence of a word with another word.
View Program →Reverse a string using a loop.
View Program →Sorts the characters of a string into alphabetical order.
View Program →Sorts the words of a sentence into alphabetical order.
View Program →Swaps the case of every letter in a string.
View Program →Check whether two strings are anagrams of each other.
View Program →Determines whether a word has no repeating letters.
View Program →Determines whether a sentence contains every letter of the alphabet.
View Program →Determines whether one string is a rotation of another.
View Program →Determines whether one string appears inside another.
View Program →Applies run-length encoding, replacing each run of a repeated character with the character and its count.
View Program →Counts how many non-overlapping times a substring appears in a string.
View Program →Generates every contiguous substring of a string.
View Program →Counts how many times each character appears in a string.
View Program →Finds every character that appears in both of two strings.
View Program →Finds every character that appears more than once in a string.
View Program →Finds the first character that appears exactly once in a string.
View Program →Finds the first character that repeats while scanning a string left to right.
View Program →Finds the last character, scanning from the end, that appears exactly once.
View Program →Finds the last character, scanning from the end, that appears more than once.
View Program →Finds the character that appears least often in a string.
View Program →Finds the longest starting substring shared by every word in an array.
View Program →Finds the character that appears most often in a string.
View Program →Removes repeated characters from a string, keeping each one's first occurrence.
View Program →Collapses runs of spaces down to a single space and trims the ends.
View Program →Reverses the letters within each word, keeping the word order intact.
View Program →Reverses the order of words in a sentence.
View Program →Generates every non-empty subsequence of a string.
View Program →Finds the longest contiguous substring that reads the same forwards and backwards.
View Program →Stores words in a prefix tree and suggests every word that starts with a typed prefix, in alphabetical order.
View Program →