Here are a few examples of simple string programs in Java:
public static String reverse(String s) {
StringBuilder sb = new StringBuilder(s);
return sb.reverse().toString();
}
public static boolean isPalindrome(String s) {
String reversed = reverse(s);
return s.equalsIgnoreCase(reversed);
}
public static int countVowels(String s) {
int count = 0;
for (char c : s.toCharArray()) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
count++;
}
}
return count;
}
public static String removeSpaces(String s) {
return s.replaceAll("\\s", "");
}
These are just a few examples, but there are many other string-related programs you can write in Java. You can find more information and examples in the Java documentation and online resources.