Reputation: 1219
I am trying to create a huge 2D array.
String[][] arr = new String[100000][100000];
But on execution, I get java.lang.OutOfMemoryError: Java heap space
Other than increasing my heap space, how do I prevent getting this exception?
Upvotes: 0
Views: 405
Reputation: 11
You can't do that Oo It make 100000*100000 = 10.000.000.000 datas for your array !
You are out of your memory !!
Reduce the two number, i don't think that you need this much memory !
You can go on a :
String[][] arr = new String[14000][14000];
I tried and it works !
Upvotes: 1
Reputation: 3643
Are you really going to use 100000 X 100000 positions, If not and you are not sure about the max limit you can start with List
of List
s
declare like this List<List<String>> arr = new ArrayList<List<String>>();
When ever you want to call you need to do this arr.get(0).get(1);
instead arr[0][1]
Upvotes: 1