to compare the memory usage between the use of the static array and java.util.ArrayList in a sorting operation -


runtime rt = runtime.getruntime();   long  totalm = rt.totalmemory();   long  currentm;    int  []n = new int[10000];   system.out.print("10000 ints used: ");   system.out.println(totalm - rt.freememory()); 

its not working. cannot use long calculation?

thanks in advance, please give me suggestions

answering implicit question in title: difference in "memory usage between use of static array , java.util.arraylist in sorting operation".

in java 8: none. because sort delegated arraylist class, sorts backing array directly using arrays.sort().

in java 7 , below, list converted array, array sorted, , result put list. so, memory doubled array, plus whatever memory need sorting operation itself, depends on version of java.
happens linkedlist in java 8.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -