Youtube Channel

Data-conversion

Data Conversion Technique
  1. Converting numerical string to numerical values
There are several generalized pre-defined static methods which is present in each and every wrapper class except character class to convert string (numerical) to fundamental values.They are as follows
Public static Xxx parseXxx(String)
Here Xxx , represents any fundamental datatypes and String represents the numerical string.
Example:
String s1=”100”;
Int n=Integer.parseInt(s1);

  1. Converting numerical object fundamental  value into string type value
To do this we use the following overloaded factory static method, present in String class.
Public static String valueOf(Xxx)
Here Xxx,represent any fundamental data type.
Example:
Int n=100;
String s1=String.valueOf(n);

  1. Converting fundamental values into object type data.
We use the following predefined gneralized parametrized constructor present in each and every wrapper class.
Int a=10;
Integer a=new Integer(a);

  1. Converting object type data into fundamental values
For this we use following generaliged pre defined instace method which is present in each and wrapper class
Public Xxx Xxxvalue();
Here Xxx represent fundamental datatypes.
Example:
Integer io=new Integer(100);
Int x=io.intValue();

  1. Converting string type data into equivalent object type data.
we use following generalized  per-defined  parametrized constructor by taking string as parameter and it is present in each and every wrapper class.
Example:
String s1=”100”;
Integer a=new Integer(s1);
 Converting object type  data into string type data
Public string toString();
Example:
Integer io=new Integer(100);
String is=io.toString();

0 comments: