Converting java long to string type_two methods and differences of converting Long type to String type in java

1. Long.ValueOf("String") returns Long packaging type data

Packaging types: Byte, Integer, Short, Long, Boolean , Character, Float, Double, etc.

2. Long.parseLong("String") returns the long basic data type

Basic data types: byte, int, short, long, boolean, char, float, double, etc.

Precautions:

1. The string cannot contain characters other than numbers, otherwise an error will be reported, java.lang.NumberFormatException

2. The length of the string should be limited, otherwise an error will be reported.

For example: String s="1234567899876543210000", if it exceeds 19 digits, an error will be reported, java.lang.NumberFormatException.

String s = "12345698798765432100", if it does not exceed, it will not be wrong.

The reason is that the maximum value of the Long type is Long.MAX_VALUE = 9223372036854775807, which is greater than the error, and the minimum value is Long.MIN_VALUE = -9223372036854775808, and an error will be reported if it is less than this value.

Related: Converting java long to string type_two methods and differences of converting Long type to String type in java