Go beyond Integer.MAX_VALUE limits in Java

Eliminating heap volume, are there any ways to go beyond Integer.MAX_VALUE limits in Java?

Examples:

  • Collections restrict Integer.MAX_VALUE.
  • StringBuilder / StringBuffer are limited to Integer.MAX_VALUE.
+3
source share
6 answers

If you have a huge collection, you will encounter all practical limitations before you ever have 2 31 - 1 in it. A collection with a million items in it will be rather cumbersome, not to mention more than a thousand times more.

, StringBuilder 2 , MAX_VALUE, .

, , -, , .

+10

? .

: , . . :

.

, , ( (-?) java), , int API java.nio.MappedByteBuffer.

+3

() . , , ( )

2 ^ 62 .

+3

Integer.MAX_VALUE, .

.

byte = 1 byte => max  2 Gb data
char = 2 byte => max  4 Gb data
int  = 4 byte => max  8 Gb data
long = 8 byte => max 16 Gb data

- , , , . "" , .

Short: Integer.MAX_VALUE is not really a limit, because you need a lot of memory to reach the limit. If you ever reach this limit, you may need to consider improving your algorithm and / or data layout :)

+2
source

Yes, with the BigInteger class.

+1
source

A memory update is required .. :)

+1
source

Source: https://habr.com/ru/post/1708163/


All Articles