I\'m trying to sort a bunch of data such that that the size of data input to the program can be larger than the memory available to the JVM, and handling that requires exter
Using the methods of Runtime, as the others suggested, is fine, as long as you take some things into consideration:
1) freeMemory() is a lower bound on the actual available memory, because memory that is unreferenced and ready for GC is considered as used. Running System.gc() before the call may return a more accurate result.
2) totalMemory() can change - it only indicates the current total heap size, and the heap can expand/shrink by the JVM during runtime, depending on its usage. You can use maxMemory() to get the actual maximum.