to check a string is palindrome or not : 

>class palindrome
>{
>	public static void main(String args[])
>	{
>		String s1=new String();
>		Scanner sc= new Scanner(System.in);
>		System.out.println("Enter the string:");
>		s1=sc.nextLine();
>		StringBuffer s2=new StringBuffer(s1);
>		s2.reverse().toString();	
>		if(s1.equals(s2.toString()))
>			System.out.println("Given String is palindrome");
		else
			System.out.println("Given String is not palindrome");
	}
}

 

this is my program code to check whether a string is palindrome or not . i get correct output using this code but i have 2 confusion [1] why cannot we use toString like s1.toString() [2]if i write if(s1.equals(s2)) simply than if condition is skipped and directly else condition is runned in output  why so?