String Conversion and to String( ) Java Help

String Conversion and to String( ) 

When Java converts data into its string representation during concatenation, it does so. by’ calling one of the overloaded versions of the string conversion method value of the ) defined by String. value is overloaded for all the simple types and for type Object. For the simple types, value.Of( ) returns ” string that contains the human-readable equivalent  the value. with which it is called. For objects, value Oft ) calls the to String() method on the object. We will look more Closely ill valuable( } later in this chapter. Here, let’s examine the to String<) method. Causeless it is the means by which you can determine the string representation for objects of classes that Yogi create. Every class implements to Singh( ) because it is defined by Object. However, the default implementation of to String( ) is seldom sufficient. For most important classes that you create, you will want to override to String( ) and provide your own string representations. Fortunately, Isis easy to do, The totting( childhood has this . general form:

String t(,String{ ) .To implement to String(), simply return a String object that contains humane-remediable~ string that appropriately describes an object of your By overriding to String() for classes that you create, you allow the resulting.strings to be fully integrated into java’s programming environment. For example, they can be used in print ) and print( ) statements and in concatenation expressions. The demonstrates this by overriding to String( ) for the Box class: The output of this program is shown here: As Box’s to String() method is automatically invoked when a Box object is, used in a concatenation expression or in a call to print.

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 17, 2014 in Staring Handling

Share the Story

About the Author

Back to Top
Share This