Created
October 12, 2016 00:30
-
-
Save alvareztech/608bcb55933ce00fade59bcfb246850f to your computer and use it in GitHub Desktop.
Ejemplos de calculo de tiempos en Java con ArrayList y LinkedList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tech.alvarez; | |
import java.util.ArrayList; | |
public class EjemploArrayList { | |
public static void main(String[] args) { | |
ArrayList<Estudiante> l = new ArrayList<Estudiante>(); | |
l.add(new Estudiante("XXXXX", "YYYYY")); | |
for (int i = 0; i < l.size(); i++) { | |
Estudiante e = l.get(i); | |
System.out.println(e.getNombres()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tech.alvarez; | |
public class Estudiante { | |
private String nombres; | |
private String apellidos; | |
public Estudiante(String nombres, String apellidos) { | |
this.nombres = nombres; | |
this.apellidos = apellidos; | |
} | |
public String getNombres() { | |
return nombres; | |
} | |
public void setNombres(String nombres) { | |
this.nombres = nombres; | |
} | |
public String getApellidos() { | |
return apellidos; | |
} | |
public void setApellidos(String apellidos) { | |
this.apellidos = apellidos; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tech.alvarez; | |
import java.util.LinkedList; | |
public class Main { | |
public static void main(String[] args) { | |
long a = System.currentTimeMillis(); | |
// codigo | |
LinkedList<Estudiante> l = new LinkedList<Estudiante>(); | |
for (int i = 0; i < 10000; i++) { | |
l.add(new Estudiante("Nombres1", "Apellidos1")); | |
} | |
// fin codigo | |
long b = System.currentTimeMillis(); | |
System.out.println(b - a); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tech.alvarez; | |
import java.util.LinkedList; | |
import java.util.ListIterator; | |
public class Principal2 { | |
public static void main(String[] args) { | |
LinkedList<Estudiante> l = new LinkedList<Estudiante>(); | |
for (int i = 0; i < 30000; i++) { | |
l.add(new Estudiante("XXXXX", "YYYYY")); | |
} | |
long a = System.currentTimeMillis(); | |
ListIterator<Estudiante> iterador = l.listIterator(); | |
while (iterador.hasNext()) { | |
Estudiante e = iterador.next(); | |
System.out.println(e.getNombres()); | |
} | |
long b = System.currentTimeMillis(); | |
long aa = System.currentTimeMillis(); | |
for (int i = 0; i < l.size(); i++) { | |
Estudiante e = l.get(i); | |
System.out.println(e.getNombres()); | |
} | |
long bb = System.currentTimeMillis(); | |
System.out.println(b - a); | |
System.out.println(bb - aa); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment