Get the long value from a system property
static Long getLong(String nm)
- Gets the long value of the system property with the specified name.
static Long getLong(String nm, long val)
- Gets the long value of the system property with the specified name.
static Long getLong(String nm, Long val)
- Gets the long value of the system property with the specified name.
The following code create a system level property with System class and then get the value in long type with Long.getLong()
public class Main {
public static void main(String[] args) {
System.setProperty("myKey", "111111111");
Long longObject = Long.getLong("myKey");
System.out.println(longObject);
}
}
The output:
111111111
In getLong(String nm, long val) and getLong(String nm, Long val) the val is the default value if no property is defined The following code tries to get the property with the name of 'myKey' and if myKey doesn't exist value '0' will return.
public class Main {
public static void main(String[] args) {
Long longObject = Long.getLong("myKey",0);
System.out.println(longObject);
}
}
The output:
0
Home
Java Book
Essential Classes
Java Book
Essential Classes
Long:
- Long class
- Constants value from Long class
- Constructors from Long
- Convert long value to byte, double, float, int, long, short
- Decode a string to create long value
- Get the long value from a system property
- Compare two long values
- Parse long value from string
- Convert long value to binary, hex and octal format strings
- Convert long value to string
- Get the sign of the long value
- Get the number of zero bits preceding and following
- Reverse and rotate a long value