/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
System .
out .
println ( "- Removendo o primeiro item/indice" ) ; executarTeste( "0" ) ;
System .
out .
println ( "- Removendo um item/indice intermediario" ) ; executarTeste( "5000" ) ;
System .
out .
println ( "- Removendo o ultimo item/indice" ) ; executarTeste( "9999" ) ;
}
private static void executarTeste
( String valueIndex
) {
ArrayList< String> array1 = new ArrayList<> ( 10000 ) ;
ArrayList< String> array2 = new ArrayList<> ( 10000 ) ;
for ( int i = 0 ; i < 10000 ; i++ ) {
array1.add ( i+ "" ) ;
array2.add ( i+ "" ) ;
}
int indice
= Integer .
valueOf ( valueIndex
) ;
long startTime
= System .
nanoTime ( ) ; array1.remove ( indice) ;
long endTime
= System .
nanoTime ( ) ;
double duration1 = ( endTime - startTime) / 1000000d;
System .
out .
println ( "Tempo de remoção do remove(index)(ms): " + String .
format ( "%.3f" , duration1
) ) ;
startTime
= System .
nanoTime ( ) ; array2.remove ( valueIndex) ;
double duration2 = ( endTime - startTime) / 1000000d;
System .
out .
println ( "Tempo de remoção do remove(Element)(ms): " + String .
format ( "%.3f" , duration2
) ) ;
System .
out .
println ( "Diferença de tempo entre as duas formas: " + String .
format ( "%.3f" ,
( duration2
- duration1
) ) ) ; }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlv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