Solved by libraries such as Eclipse collections: https://www.baeldung.com/java-eclipse-primitive-collections which has memory-optimized lists, sets, stacks, maps, and bags for all the primitive types
And that’s not one-time work. In the ideal world, if the size of your data grows (or shrinks), you’ll have to revisit those choices.
Also, as a library author, you can’t know what choice to make.
Yes, you’ll always have that problem, but this change would make ‘just use the provided collections’ a much safer choice.
Usually you just pick fastuil or kobloke and then use it every time.
Edit: as comments below corroborate.