Gayatri Mishra | https://www.linkedin.
com/in/gayatri-mishra-freelancecoach/
Gayatri Mishra | https://www.linkedin.com/in/gayatri-mishra-freelancecoach/
A short into to Wrapper class in java with example :
Java Wrapper classes wrap the primitive data types, that is why it is known as wrapper classes.
Wrapper classes we commonly use :
Integer
Double
Float
These classes are very much useful in converting data like converting string to any primitive data type int ,
double , float ect.
How can we use wrapper class ?
String s = “49600.90”;
Let’s say we need to convert the string into decimal to perform further operations.
We can follow below steps.
Step-1:
1. Initialize the string or get the dynamically and store the same in string variable using getText()
method.
String s1=”496000.90”
2. Declare the double variable.
double amount;
3. Convert the string to double:
amount = Double.ParseDouble(s1); // pass the string as parameter
4. Print the amount.
System.out.println(“The amount of the item is “ + amount);
Note : Please check the below sample code
Gayatri Mishra | https://www.linkedin.com/in/gayatri-mishra-freelancecoach/