source code Integer
package wclasses;
public class SampleInteger {
public static void main(String att[])
{
//constructors
Integer i1= new Integer(10);
Integer i2= new Integer("10");
// wrapper to primitive
int pi1=i1.intValue();
System.out.println(pi1);
//binary,octa,hexa notations.
String bin=Integer.toBinaryString(10);
System.out.println(bin);
String oct=Integer.toOctalString(12);
System.out.println(oct);
String hex=Integer.toHexString(12);
System.out.println(hex);
//primitive to string
String s1=i1.toString();
String s2=Integer.toString(10);
System.out.println(s1);
System.out.println(s2);
//String to primitive
int pi2=Integer.parseInt(s2);
System.out.println(pi2);
//String to wrapper object
Integer i3= new Integer("10");
Integer i4=Integer.valueOf("100");
System.out.println(i3);
System.out.println(i4);
//wrapper to string
String s3=i4.toString();
}
}
output:
10
1010
14
c
10
10
10
10
100
0 comments:
Post a Comment