tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid...@pidster.com>
Subject Re: sort an array
Date Tue, 27 Jun 2006 08:10:50 GMT
You put the compareTo object on the object to be compared.
You could also try:

 java.utils.Arrays.sort(Object[] array, Comparator comp)

There are plenty of tutorials to be found via Google on the use of both
this and Collections.sort().


password password wrote:
> Please, can you put an example? I don't know how put the compareTo Method in my servlet.
> 
> Sérgio Costa <oscilate@gmail.com> escribió:  Put them in a list and Collections.sort()
them.
> 
> All you'll need to do is create a Class with all those fields implementing
> Comparable, and implement the compareTo Method.
> 
> hope it helps
> SC
> 
> On 6/26/06, password password wrote:
>> Hi,
>>
>> I have a servlet and in this servlet I have a problem when sort an
>> array. If in Tomcat 5.5.4 (on windows) the order is very fast (about 2
>> seconds) , but in tomcat 5.5.9 is slower (about 25 seconds). I don't Know
>> why the same code has diferent time.
>> The code is the next. The array has 7000 elements.
>>
>> //////////////////////////////////////////////////////////////////////////////////////////////////////////
>> java.util.Date datTiempoInicio, datTiempoFin;
>> java.util.Calendar calTiempoInicio = Calendar.getInstance();
>> java.util.Calendar calTiempoFin = Calendar.getInstance();
>> long intTiempoUtilizado;
>> datTiempoInicio = new java.util.Date();
>> calTiempoInicio.setTime(datTiempoInicio );
>>
>> if (astrName.length > 1) {
>> //ordenacion de los arrays: astrName[intFilaArray]
>> int i, pasadas;
>> String strTemp;
>> double dblIntensityTemp;
>> double dblBackgroundTemp;
>> int intComparacion;
>> for (pasadas = 1; pasadas < astrName.length; pasadas++) {
>> for (i = 0; i> intComparacion = astrName[i].compareTo(astrName[i+1]);
>> if (intComparacion > 0) {
>> strTemp = astrName[i];
>> astrName[i] = astrName[i + 1];
>> astrName[i + 1] = strTemp;
>> dblIntensityTemp = adblIntensity1[i];
>> adblIntensity1[i] = adblIntensity1[i + 1];
>> adblIntensity1[i + 1] = dblIntensityTemp;
>> dblIntensityTemp = adblIntensity2[i];
>> adblIntensity2[i] = adblIntensity2[i + 1];
>> adblIntensity2[i + 1] = dblIntensityTemp;
>> dblBackgroundTemp = adblBackground1[i];
>> adblBackground1[i] = adblBackground1[i + 1];
>> adblBackground1[i + 1] = dblBackgroundTemp;
>> dblBackgroundTemp = adblBackground2[i];
>> adblBackground2[i] = adblBackground2[i + 1];
>> adblBackground2[i + 1] = dblBackgroundTemp;
>> } // end if (intComparacion > 0)
>> } //end for i
>> } //end for pasadas
>>
>> } // end if (astrName.length > 1)
>>
>> datTiempoFin = new java.util.Date();
>> calTiempoFin.setTime(datTiempoFin );
>>
>> intTiempoUtilizado = Math.abs( (calTiempoFin.getTimeInMillis() -
>> calTiempoInicio.getTimeInMillis()) / (1000) );
>> System.out.println("(ProcessFile) Time = " + intTiempoUtilizado );
>>
>> ////////////////////////////////////////////////////////////////////////////////////////////////
>>
>>
>> Can You help me?
>>
>>
>>
>> ---------------------------------
>>
>> LLama Gratis a cualquier PC del Mundo.
>> Llamadas a fijos y móviles desde 1 céntimo por minuto.
>> http://es.voice.yahoo.com
>>
> 
> 
>  		
> ---------------------------------
> 
> LLama Gratis a cualquier PC del Mundo.
> Llamadas a fijos y móviles desde 1 céntimo por minuto.
> http://es.voice.yahoo.com


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message