1 Long.parseLong("0", 10) // returns 0L
2 Long.parseLong("473", 10) // returns 473L
3 Long.parseLong("-0", 10) // returns 0L
4 Long.parseLong("-FF", 16) // returns -255L
5 Long.parseLong("1100110", 2) // returns 102L
6 Long.parseLong("99", 8) // throws a NumberFormatException
7 Long.parseLong("Hazelnut", 10) // throws a NumberFormatException
8 Long.parseLong("Hazelnut", 36) // returns 1356099454469L
9 Long.parseLong("999") // returns 999L
1public class Example {
2 public static void main(String[] args)
3 {
4 String str = "11111";
5 String str2 = "88888";
6 //Conversion using valueOf(String) method
7 long num = Long.valueOf(str);
8 long num2 = Long.valueOf(str2);
9 System.out.println(num+num2);
10 }
11}
12Output:
1399999
1public class Example {
2 public static void main(String[] args)
3 {
4 String str = "10000";
5 String str2 = "22222";
6 //Conversion using Long(String s) constructor
7 long num = new Long(str);
8 long num2 = new Long(str2);
9 System.out.println(num*num2);
10 }
11}
12Output:
13222220000