-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArraylist 2.java
More file actions
29 lines (24 loc) · 763 Bytes
/
Arraylist 2.java
File metadata and controls
29 lines (24 loc) · 763 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
import java.util.*;
class Persona{
private String nombre;
public Persona(String nom){
nombre=nom;
}
public String getNombre(){
return nombre;
}
}
public class Ejemplo2Funcional {
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,
(Persona p1,Persona p2)-> p1.getNombre().compareTo(p2.getNombre())
);
milista.stream().filter(p -> !p.getNombre().startsWith("M"))
.forEach(p -> System.out.println(p.getNombre()));
}
}