java 各基本数据类型 所占有的字节数

 

Int: 4 字节
Short: 2字节
Long: 8字节
Byte: 1字节
Character: 2字节
Float: 4字节
Double: 8字节

Boolean:系统没有提供Size方法;

 
  1. public class Calcsizof {

  2.  
  3. /**

  4. * @param args

  5. */

  6. private static void calSize() {

  7. System.out.println("Integer: " + Integer.SIZE/8); // 4

  8. System.out.println("Short: " + Short.SIZE/8); // 2

  9. System.out.println("Long: " + Long.SIZE/8); // 8

  10. System.out.println("Byte: " + Byte.SIZE/8); // 1

  11. System.out.println("Character: " + Character.SIZE/8); // 2

  12. System.out.println("Float: " + Float.SIZE/8); // 4

  13. System.out.println("Double: " + Double.SIZE/8); // 8

  14. System.out.println("Boolean: " + Boolean.toString(false));

  15.  
  16. }

  17. public static void main(String[] args) {

  18. // TODO Auto-generated method stub

  19. Calcsizof calcsizof= new Calcsizof();

  20. Calcsizof.calSize();

  21. }

  22. }

运行结果:console 输出

Integer: 4
Short: 2
Long: 8
Byte: 1
Character: 2
Float: 4
Double: 8
Boolean: false

更多地封装后的Object的占用空间的分析 请参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值