Ads Sponsored By Google :)

Sunday, 13 January 2013

Wrapper | Data class conversions in java with example

Wrapper class conversions in java Data conversions in java Wrapper class conversions in java with example Data conversions in java with example


Wrapper or Data Conversions in java:
          In java programming we have six conversions we come across in software development                             
         they are.
        
        1)      Converting String value to fundamental  / numerical value:
              In order to convert string values to fundamental values we use the following method which                               
        is present in each and every wrapper class name.

      Syntax:
         Public static Xxx parse(String)
                    Here Xxx represents any fundamental data type.
     For Example:
1)        String s1=”100”;
                     int x=Integer.parseInt(s1);
2)      String s2=”10.75f”;
                   float y=Float.parseFloat(s2);
    
         2)      Converting Fundamental values into String values:
            In order to convert fundamental  /  numerical values into string values  we need to
         use the following generalized predefined overloaded factory method.
      Syntax:
            Public static final String valueOf(Xxx);
             Here Xxx represents fundamental data type.

    For Example:
          int x=18;
          String s1=String.valueOf(x);
      
       3)      Converting Fundamental values into Object form:
                   In order to convert fundamental values into object form we use the following generalized 
       pre-defined  parameterized constructors. which are taking fundamental values as parameters 
       as they present in wrapper classes.
      
      Syntax:
         Wrapperclassname(Xxx);
         Here Xxx represents fundamental data type.
       For Example:        
           int  a=100;
           Integer i=new Integer(a);

       4)      Converting  Object data into fundamental value:
                  In order to convert Object data into fundamental  /  numerical values  we need to use 
      the following generalized predefined instance method.
    
      For Example:
Public Xxx Xxxvalue();
Here Xxx represents any fundamental data type.

       5)      Converting String data into wrapper class object:
                         In order to convert string values into wrapper class  object we need to use the 
      following generalized predefined parameterized constructor taking string as a parameter.

   Syntax:
           Wrapperclassname(String);

      6)      Converting wrapper class object to String data:
      In order to convert wrapper class  object into string values .we need to use the following generalized  
   predefined instance method.
   Syntax:
           Public String toString();

No comments:

Post a Comment

LinkWithin