All Possible Unique combination of Palindrome substring from a Given String

All Possible Unique combination of Palindrome substring from a Given String
SOURCE : DifferentCominationOfPERMUTAION.java


import java.util.HashSet;


public class DifferentCominationOfPERMUTAION {

public static void main(String[] args) {
String str = "aaabbbcccdddjdjzscijsghfy";

HashSet hs = new HashSet<>();
for (int i = 0; i < str.length(); i++) {
for (int j = i + 1; j <= str.length(); j++) {

if (isplaind(str.substring(i, j)))
hs.add(str.substring(i, j));

}
}
System.out.println(hs);

}

private static boolean isplaind(String str) {

if (str.length() > 0) {

for (int i = 0, j = str.length() - 1; i <= j; i++, j--) {

if (str.charAt(i) == str.charAt(j)) {
continue;

} else
return false;
}
return true;

}

return false;
}
}


INPUT

String str = "aaabbbcccdddjdjzscijsghfy";



OUTPUT

[aa, aaa, bb, cc, dd, a, b, ccc, bbb, c, d, ddd, f, g, h, i, j, jdj, s, y, z, djd]






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment