1 / 7

Data conversion using valueof()

Data conversion using valueof(). Priyankar ojah dc2012mca0023. Introduction.

senwe
Download Presentation

Data conversion using valueof()

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data conversion using valueof() Priyankarojah dc2012mca0023

  2. 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.

  3. 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[])

  4. 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) • {

  5. Width=w; • Height=h; • Depth=d; • } • Public String toString() • { • Return “dimensions are”+width+”by”+depth+”by”+height+”.”; • } • }

  6. 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); • } • }

  7. The output of the program is : • Dimensions are 10 by 14 by 12. • Box b: dimensions are 10 by 14 by 12.

More Related