How to make a big array in java

后端 未结 5 677
抹茶落季
抹茶落季 2020-12-20 17:44

I want to create a boolean array of a size which the user is going to put as input.For example - The user might put a big number like 1000000000000 ; so then I have to creat

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 18:22

    How about using a HashMap and use long keys and boolean values.

    There you have several advantages.
    1. You can use indexes within the range of long
    2. You don't have to worry about the maximum size of item index that is used. As long as it is a long it will work
    3. You don't allocate memory for the entire collection up front. Instead you will only use the memory that you need.

提交回复
热议问题