I played with some sample collections from the Oracle site
public class Timing { public static void method(){ List numbers = new ArrayList(); for (double i = 1; i <= Double.MAX_VALUE; i++) numbers.add(new Double(i)); Collections.shuffle(numbers); List winningcombination = numbers.subList(0, 10); Collections.sort(winningcombination); } public static void main(String[] args) { long start = System.currentTimeMillis(); method(); long end = System.currentTimeMillis(); System.out.println("time elapsed : " + (end-start)); } }
I tried to see how long it would take to do for Double.MAX_VALUE. And I got this:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Unknown Source) at java.util.Arrays.copyOf(Unknown Source) at java.util.ArrayList.ensureCapacity(Unknown Source) at java.util.ArrayList.add(Unknown Source)
Is there any way to fix this?
source share