70 likes | 264 Views
Data conversion using valueof(). Priyankar ojah dc2012mca0023. Introduction.
E N D
Data conversion using valueof() Priyankarojah dc2012mca0023
Introduction • The valueof() method converts data form its internal format into human-readable form .It is a static method that is overloaded whiten string for all of java’s-built-in types ,so that each type can be converted properly into a string.
Data conversion using valueof() • The valueof() method converts data form its internal format into human-readable form • It is a static method that is overloaded within string for all of java’s built-in type ,so that each type can be converted into a string. • valueof() is also overloaded for type object ,so an object of any class type we create can also be use as an argument Here are a few of its form: static String valueOf(double num) static String valueOf(long num) static String valueOf(Object ob) static String valueOf(char chars[])
Any object that we pass to valueof() will return the result of a call to the object’s toString() method. In fact we could just call toString() dirctly and get some result. • For example: • Class box • { • Double width; • Double height; • Double depth; • Box(double w,doubleh,double d) • {
Width=w; • Height=h; • Depth=d; • } • Public String toString() • { • Return “dimensions are”+width+”by”+depth+”by”+height+”.”; • } • }
Class toStringDemo • { • Public static void main(String args[]) • { • Box b=new box(10,12,14); • String s=“box b:”+b; • System.out.println(b); • System.out.println(s); • } • }
The output of the program is : • Dimensions are 10 by 14 by 12. • Box b: dimensions are 10 by 14 by 12.