string palindrome in java without using inbuilt function or method code example
Example 1: Java program to check whether string is palindrome using library methods
public class StringPalindromeJava
{
public static void isPalindrome(String str)
{
String strReverse = new StringBuffer(str).reverse().toString();
if(str.equals(strReverse))
{
System.out.println(str + " is palindrome string.");
}
else
{
System.out.println(str + " is not palindrome string.");
}
}
public static void main(String[] args)
{
isPalindrome("eye");
isPalindrome("rotator");
}
}
Example 2: String palindrome in java using stringbuffer
public class PalindromeUsingStringBuffer
{
public static void main(String[] args)
{
String strInput = "nayan";
StringBuffer sb = new StringBuffer(strInput);
sb.reverse();
String str = sb.toString();
if(strInput.equals(str))
{
System.out.println("string is palindrome.");
}
else
{
System.out.println("string is not palindrome.");
}
}
}