![enter image description here](https://i.stack.imgur.com/37B5W.png)
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class GetAllPalindromes
{
static Scanner in;
public static void main(String[] args)
{
in = new Scanner(System.in);
System.out.println("Enter a string \n");
String abc = in.nextLine();
Set a = printAllPalindromes(abc);
System.out.println("set is " + a);
}
public static Set<CharSequence> printAllPalindromes(String input)
{
if (input.length() <= 2) {
return Collections.emptySet();
}
Set<CharSequence> out = new HashSet<CharSequence>();
int length = input.length();
for (int i = 1; i < length - 1; i++)
{
for (int j = i - 1, k = i + 1; j >= 0 && k < length; j--, k++)
{
if (input.charAt(j) == input.charAt(k)) {
out.add(input.subSequence(j, k + 1));
} else {
break;
}
}
}
return out;
}
}
**Get All Palindrome in s given string**
выход
D: \ Java> Java GetAllPalindromes
Введите строку
Привет, пользователь, нитин, мой лучший друг, вау!
Ответ набор [нитин, нитин, вау, вау, ити]
D: \ Java>