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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -