go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Collection Sorting: Static vs. Dynamic
 
Subject: Collection Sorting: Static vs. Dynamic
Author: EricJ
Posted on: 02/17/2009 08:51:40 PM


Static Collection Sorting: java.util.Collections.sort()

public class StaticSorting
{
    public static void main(String[] argv)
    {
        long t1, t2;
        int max = 1000000;
		
        t1=System.currentTimeMillis();
		
        List myList = new ArrayList();
        for(int i=0; i<max; i++){
            myList.add("ABCDEFG"+Math.random()*100000);
        }
        Collections.sort(myList);
		
        t2=System.currentTimeMillis();
		
        Runtime rt = Runtime.getRuntime();
        long memoryUsed = rt.totalMemory() - rt.freeMemory();
        System.out.println(myList.get(0));
        System.out.println("Time consumed="+(t2-t1)+" (ms)   Memory used="+memoryUsed+ "(bytes)" );
    	
    }
}


Here is the output:

ABCDEFG0.3944624056728685
Time consumed=10813 (ms) Memory used=103774088(bytes)


Replies:


References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.