-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrapperParser.java
37 lines (29 loc) · 1.11 KB
/
WrapperParser.java
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
35
36
37
/*
* Parse strings using wrapper classes and constants of these.
* Example shows how to create primitive data types such as
* byte,short,int,... from strings.
* wrapper class constants: MIN_VALUE, MAX_VALUE, NEGATIVE_INFINITY,
* POSITIVE_INFINITY
*/
public class WrapperParser{
public static void main(String[] args) {
String intString = "501";
String byteString = "127";
String booleanString = "true";
String doubleString = "2014.2013";
String floatString = "2014.2";
int numberInt = Integer.parseInt(intString);
System.out.println("\n" + numberInt);
byte numberByte = Byte.parseByte(byteString);
System.out.println("\n" + numberByte);
boolean valueBoolean = Boolean.parseBoolean(booleanString);
System.out.println("\n" + valueBoolean);
double numberDouble = Double.parseDouble(doubleString);
System.out.println("\n" + numberDouble);
double numberFloat = Float.parseFloat(floatString);
System.out.println("\n" + numberFloat);
// constants in wrapper classes
System.out.println("smalles short number: " + Short.MIN_VALUE);
System.out.println("smalles float number: " + Float.MIN_VALUE);
}
}