Saturday, August 31, 2019

How to Convert Integer To Long in Java

you can't cast Integer to Long, even though you can convert from int to long. For an individual value which is known to be a number and you want to get the long value, you could use:

package com.mkyong.example;

public class TestInteger {

    public static void main(String[] args) {

        Integer num = 1;

        System.out.println(num);            // 1

        Long numInLong = Long.valueOf(num);

        System.out.println(numInLong);      // 1

    }
}



0 komentar:

Post a Comment