Saturday, February 28, 2009

source code Long class



package wclasses;

public class SampleLong {
public static void main(String att[])
{
//constructors
Long l1= new Long(10);
Long l2= new Long("10");

// wrapper to primitive
int pl1=l1.intValue();
long l0=l1.longValue();
System.out.println(pl1);

//binary,octa,hexa notations.
String bin=Long.toBinaryString(10);
System.out.println(bin);
String oct=Long.toOctalString(12);
System.out.println(oct);
String hex=Long.toHexString(12);
System.out.println(hex);

//primitive to string
String s1=l1.toString();
String s2=Long.toString(10);
System.out.println(s1);
System.out.println(s2);

//String to primitive
long pl2=Long.parseLong(s2);
System.out.println(pl2);

//String to wrapper object
Long l3= new Long("10");
Long l4=Long.valueOf("100");
System.out.println(l3);
System.out.println(l4);

//wrapper to string
String s3=l4.toString();


}
}

output:
10
1010
14
c
10
10
10
10
100


0 comments:

Post a Comment