Does the memory usage of Java Int to String become larger?

What is a byte

Byte.

  • Byte is one of Java’s basic types.

  • In Java it ranges from -128 to 127, and the default value is 0.

  • Byte The data type is 8 bits. One byte equals 8 bits. Bit is the minimum unit for transmitting information.

  • Byte types are used to save space in large arrays, mainly in place of integers, because byte variables take up only a quarter of the space of ints

Memory analysis

String In THE ASCII code: 1 byte in Chinese and 2 bytes in Chinese

(The number of Chinese bytes in a String depends on the encoding set used. If the String is utF-8, the number of Chinese bytes in a String is 3. If the String is GBK or GB2312, the number of Chinese bytes in a String is 2.)

conclusion

Since an int takes up four bytes, an int becomes a character when it is transformed into a string, and an English character or digit takes up one byte, an int with less than four digits takes up less memory than an int with more than four digits.