09 Java Streams y Manipulación de Datos Flashcards

1
Q

¿Qué es un Stream en Java?

A

Una secuencia de elementos que permite operaciones funcionales sobre datos.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

¿Cómo se obtiene un Stream a partir de una lista?

A

Usando list.stream().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

¿Qué hace filter() en un Stream?

A

Filtra elementos según un predicado booleano.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

¿Qué hace map() en un Stream?

A

Transforma cada elemento aplicando una función.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

¿Qué hace sorted() en un Stream?

A

Ordena los elementos en orden natural o usando un comparador.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

¿Qué hace distinct() en un Stream?

A

Elimina elementos duplicados.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

¿Qué hace limit(n) en un Stream?

A

Restringe el número de elementos en la secuencia.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

¿Qué hace skip(n) en un Stream?

A

Omite los primeros n elementos.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

¿Qué hace collect(Collectors.toList())?

A

Convierte el Stream en una lista.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

¿Qué hace reduce() en un Stream?

A

Combina elementos en un solo resultado utilizando una función acumuladora.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

¿Qué hace allMatch() en un Stream?

A

Verifica si todos los elementos cumplen una condición.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

¿Qué hace anyMatch() en un Stream?

A

Verifica si al menos un elemento cumple una condición.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

¿Qué hace noneMatch() en un Stream?

A

Verifica si ningún elemento cumple una condición.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

¿Qué hace findFirst() en un Stream?

A

Devuelve el primer elemento si está presente.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

¿Qué hace findAny() en un Stream?

A

Devuelve cualquier elemento disponible (útil en streams paralelos).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

¿Qué diferencia hay entre forEach() y map()?

A

forEach() ejecuta una acción sin modificar, map() transforma los elementos.

17
Q

¿Qué es Collectors.groupingBy()?

A

Un colector que agrupa elementos en un Map.

18
Q

¿Qué es Collectors.partitioningBy()?

A

Divide elementos en dos grupos según un predicado.

19
Q

¿Cómo hacer que un Stream sea paralelo?

A

Usando stream.parallel().

20
Q

¿Cuándo es recomendable usar Stream.parallel()?

A

Cuando hay un gran volumen de datos y procesamiento costoso.