Monthly Archives: October 2015

Boxing , Unboxing

Converting from a primitive type to its corresponding reference type is boxing conversion and vice versa is unboxing conversion.

Examples are,

  • From primitive boolean to type Boolean
  • From primitive int to type Integer
	int i = 10;
	Integer iObj = new Integer(100);

	iObj = i;//boxing conversion
	i = iObj;//unboxing conversion
Advertisements

Check Whether Number is Palindrom

For Number:

private static boolean isPalindrome(int number){

int orignalNo = number;
int reverse = 0;
while(number != 0){
reverse = reverse*10 + number%10;
number = number/10;
}
return (orignalNo == reverse);
}

For String:

private static boolean isPalindrome(String pText){

for ( int i = pText.length() – 1; i >= 0; i– )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println(“Entered string is a palindrome.”);
else
System.out.println(“Entered string is not a palindrome.”);

References

http://javarevisited.blogspot.com/2012/12/how-to-check-if-number-is-palindrome-or-not-example.html

http://www.programmingsimplified.com/java/source-code/java-program-check-palindrome