public class MainTest {
public static void main(String args[]) throws Exception {
System.out.println("int占的字节:"+Integer.BYTES);
System.out.println("long占的字节:"+Long.BYTES);
System.out.println("short占的字节:"+Short.BYTES);
System.out.println("char占的字节:"+Character.SIZE/8);
System.out.println("float占的字节:"+Float.SIZE/8);
System.out.println("double占的字节:"+Double.SIZE/8);
}
}
输出:
int占的字节:4
long占的字节:8
short占的字节:2
char占的字节:2
float占的字节:4
double占的字节:8
注意.BYTES返回的是字节数byte,而.SIZE返回的是比特数bit,所以要除以8