-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayList2Imperativo.java
More file actions
31 lines (28 loc) · 858 Bytes
/
ArrayList2Imperativo.java
File metadata and controls
31 lines (28 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
class Persona{
private String nombre;
public Persona(String nom){
nombre=nom;
}
public String getNombre(){
return nombre;
}
}
public class Ejemplo2Imperativo {
public static void main(String[] args) {
ArrayList<Persona> milista= new ArrayList<Persona>();
milista.add(new Persona("Mariano"));
milista.add(new Persona("Sergi"));
milista.add(new Persona("Laura"));
milista.add(new Persona("Miguel"));
Collections.sort(milista,new Comparator<Persona>() {
public int compare(Persona p1,Persona p2) {
return p1.getNombre().compareTo(p2.getNombre());
}
});
for (Persona p: milista) {
if(!p.getNombre().startsWith("M"))
System.out.println(p.getNombre());
}
}
}