forked from maheshashokit/27_Java_Full_Stack_Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringToObject.java
More file actions
34 lines (22 loc) · 965 Bytes
/
StringToObject.java
File metadata and controls
34 lines (22 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class StringToObject {
public static void main(String[] args) {
//In Java We can Store numbers as String format i.e.,enclosed with ""
String no = "145";
String floatNo = "123.456f";
String doubleNo = "123.34556d";
//1.Passing numbers as string to Wrapper Class Constructor
Integer i1 = new Integer(no);
Float f1 = new Float(floatNo);
Double d1 = new Double(doubleNo);
System.out.println("Object i1 :::::" + i1);
System.out.println("Object f1 :::::" + f1);
System.out.println("Object d1 :::::" + d1);
//2.Converting the numbers as String using static method of Wrapper class
Integer intValue = Integer.valueOf(no);
Float floatValue = Float.valueOf(floatNo);
Double doubleValue = Double.valueOf(doubleNo);
System.out.println("Object intValue :::::" + intValue);
System.out.println("Object floatValue :::::" + floatValue);
System.out.println("Object doubleValue :::::" + doubleValue);
}
}