How can I convert a long to int in Java?

后端 未结 16 2206
余生分开走
余生分开走 2020-11-29 16:49

How can I convert a long to int in Java?

16条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 17:30

    You can use the Long wrapper instead of long primitive and call

    Long.intValue()
    

    Java7 intValue() docs

    It rounds/truncate the long value accordingly to fit in an int.

提交回复
热议问题