option
Cuestiones
ayuda
daypo
buscar.php

Certificación Java Parte 7

COMENTARIOS ESTADÍSTICAS RÉCORDS
REALIZAR TEST
Título del Test:
Certificación Java Parte 7

Descripción:
Lambdas, Interfaces Funcionales,Streams

Fecha de Creación: 2024/01/31

Categoría: Otros

Número Preguntas: 27

Valoración:(0)
COMPARTE EL TEST
Nuevo ComentarioNuevo Comentario
Comentarios
NO HAY REGISTROS
Temario:

Relaciona cada interfaz funcional con la función que realiza. Interfaz Predicate <T>. Interfaz Function <T,R>. Interfaz Consumer <T>. Interfaz Supplier <T>. Interfaz UnaryOperator <T>.

La siguiente Interfaz ¿Se puede considerar Funcional?: interface Hablar{ void decirFrase(String frase); default void saludar(){ System.out.println("Hola"); } static void metodoEstatico(){}; }. Si. No.

Escoge las implementaciones correctas de las siguientes expresiones lambda. () ->6. -> 8. int a -> System.out.println("Frase"). x -> x+x. x,y -> x-y. x -> return x/x. (x,y)->{ x *= 2; System.out.println(x+y); }. (var a) -> System.out.println(a). (var a, int c) ->a+c.

Une cada Interfaz funcional con su implementación correspondiente. interface inter1 {int metodo1(String);}. interface inter2 {int metodo2(int x,int y);}. interface inter3 {void metodo3();}. interface inter4 {String metodo2(int x);}.

Une cada Interfaz funcional con su métodos correspondientes. Interfaz Predicate <T>. Interfaz Function <T,R>. Interfaz Consumer <T>. Interfaz Supplier <T>. Interfaz UnaryOperator <T>.

Relaciona cada interfaz funcional con el método que usa su implementación. Interfaz Predicate <T>. Interfaz Function <T,R>. Interfaz Consumer <T>. Interfaz Supplier <T>. Interfaz UnaryOperator <T>.

A partir de este fragmento de código: var nums=List.of(1,2,3,4,5,6); //line 1 StringBuilder sb=new StringBuilder(); for(int n:nums){ sb.append(f.apply(n)); sb.append(" "); } System.out.println(sb.toString()); ¿Qué debemos añadir en la linea 1 para que compile correctamente?. Function<Integer, Integer> f=n->n*2;. Function<Integer> f = n −> n * 2;. Function<int> f = n −> n * 2;. Function<int, int> f = n −> n * 2;. Function f = n −> n * 2;.

Selecciona las opciones correctas para crear un Stream. ArrayList<Integer> miArray= new ArrayList<>(); miArray.add(1);miArray.add(2); Stream<Integer> miStream = miArray.stream();. String[] letras= {“a”,”b”,”c”,”d”}; Stream <String> miStream = Arrays.stream(letras);. Stream<Double> miStream = Stream.of(4, 6, 2);. IntStream miStreamInt= IntStream.range(1,10);. String[] letras= {“a”,”b”,”c”,”d”}; Stream <String> miStream = letras.stream(letras);. Stream miStreamInt= IntStream.range(1,10);.

Elige la opción correcta sobre los métodos de los Stream. Métodos intermedios. Métodos finales.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { List<String> miLista = new ArrayList<>(List.of("uno","dos","tres","cuatro","uno","dos")); Stream<String> miStrm = miLista.stream(); miStrm.distinct().filter((a)->a.length()<=3).forEach(System.out::println); }. uno dos uno dos. uno dos. uno dos tres. no devuelve nada.

Selecciona cada método de Stream con la interfaz funcional que recibe como parámetro. forEach. filter. anyMatch allMatch noneMatch. max. map. flatmap. peak. sorted. reduce.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { List<String> miLista = new ArrayList<>(List.of("uno","dos","tres","cuatro","uno","dos")); Stream<String> miStrm = miLista.stream(); System.out.println(miStrm.distinct().anyMatch((a) -> a == "uno")); }. True. False. uno.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { List<String> miLista = new ArrayList<>(List.of("uno","dos","tres","cuatro","uno","dos")); Stream<String> miStrm = miLista.stream(); miStrm.distinct().skip(3).forEach(System.out::println); }. cuatro uno dos. tres cuatro uno dos. cuatro. uno dos tres.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { List<String> miLista = new ArrayList<>(List.of("uno","dos","tres","cuatro","uno","dos")); Stream<String> miStrm = miLista.stream(); miStrm.distinct().limit(2).forEach(System.out::println); }. uno dos. uno. uno dos tres.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { Stream<Integer> miStream = Stream.of(1,2,3,4,5); System.out.println(miStream.filter((n)-> n%2==0).count()); }. 2. 2 4. 0. 1 3 5.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { Stream<Integer> miStream = Stream.of(1,3,5); System.out.println(miStream.filter((n)-> n%2==0).findFirst()); }. false. Un objeto Opcional vacío. NullPointerException. nada.

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { Stream<Integer> miStream = Stream.of(1,2,3,5); System.out.println(miStream.filter((n)-> n%2==0).findFirst()); }. 2. Opcional vacio. Error de compilación. Optional[2].

¿Qué devolverá el siguiente fragmento de código? public static void main(String[] args) { Stream<Integer> miStream = Stream.of(1,2,3,5); Optional opt = miStream.filter((n)-> n%2==0).findFirst(); if(opt.isEmpty()){ System.out.println("No se encuentra"); }else{ System.out.println("El primer número par es " + opt.get()); } Stream<Integer> miStream2 = Stream.of(1,2,3,5); Optional<Integer> opt2 = miStream2.filter((n)-> n>6).findFirst(); System.out.println(opt2.orElse(0)); }. No se encuentra Optional vacío. El primer número par es 2 Optional vacío. El primer número par es 2 0. No se encuentra 0.

¿Que resultado se imprimirá por pantalla? List<String> nombres= Arrays.asList("Juan Jose", "Ramon", "Alvaro"); boolean isSame= nombres.stream().allMatch(nom->{ System.out.println("Nombre : "+ nom); return str.equals("Juan"); }); System.out.println(isSame);. Juan Jose False. Juan Jose Ramon Alvaro. Error de compilación.

¿Cual será el resultado de este fragmento de código? List<Persona> per = new ArrayList(List.of(new Persona(20, "Juan"), new Persona(20, "Alberto"), new Persona(43, "Luis"))); per.sort(Comparator.comparing(Persona::getEdad).thenComparing(Persona::getNombre).reversed()); per.forEach(p -> System.out.println("Nombre " + p.getNombre()));. Nombre Luis Nombre Juan Nombre Alberto. Nombre Alberto Nombre Juan Nombre Luis. Nombre Juan Nombre Pedro Nombre Luis.

Dado el siguiente fragmento de código ¿Qué devolverá por pantalla? public static void main(String[] args) { Stream <Integer> numeros = Stream.of(2,3,5,7,8); numeros.peek(n-> System.out.print(n+",")).allMatch(n->n<5); }. 2,3,5,7,8. No se muestra nada. 2,3. 2,3,5.

¿Cuál será el resultado de este fragmento de código? public static void main(String[] args) { var numeros = List.of(1, 2, 3, 4, 5, 6, 7).stream(); Predicate<Integer> p = a -> a < 4; Optional<Integer> value = numeros.filter(p).reduce((a, b)->a+b); value.ifPresent(System.out::println); }. No muestra nada por pantalla. 6. 28. 10.

¿Cuál será el resultado de este fragmento de código? public static void main(String[] args) { var numeros = List.of(2,4,6,8); double media = numeros.parallelStream().mapToInt(m->m).average().getAsDouble(); System.out.println(media); }. 20. No imprime nada por pantalla. Error de compilación.

¿Cuál será el resultado de este fragmento de código? public static void main(String[] args) { int[][] numeros = {{3,4},{5,6},{7,8}}; long count = Stream.of(numeros).flatMapToInt(IntStream::of) .map(n-> n + 1) .filter(n -> (n % 2) ==0 ) .peek(System.out::print) .count(); System.out.println(count); }. 4683. 3456783. 3. Error de compilación.

Dado el siguiente fragmento de código ¿Qué se mostrará por pantalla? public static void main(String[] args) { Stream<Personas> str2 = Stream.of(new Personas("Pedro",23),new Personas("Juan",32) ,new Personas("Ana",56),new Personas("Antonio",23)); Map <Integer, List<Personas>> personas = str2.collect(Collectors.groupingBy(p->p.getEdad())); personas.forEach((k,v)-> { System.out.println(k); v.forEach(n -> System.out.println(n.getNombre()));} ); }. Error de compilación. 32 Juan 23 Pedro Antonio 56 Ana. 32 23 56 Juan Pedro Antonio Ana. No se imprime nada por pantalla.

Dado el siguiente fragmento de código ¿Qué se mostrará por pantalla? Stream<Personas> str3 = Stream.of(new Personas("Pedro",23),new Personas("Juan",17) ,new Personas("Ana",15),new Personas("Antonio",23)); Map <Boolean,List<Personas>> per = str3.collect(Collectors.partitioningBy(p->p.getEdad()>18)); per.forEach((k,v)-> { System.out.println(k); v.forEach(n-> System.out.println(n.getNombre())); });. 15 Ana 17 Juan 23 Pedro Antonio. false Juan Ana true Pedro Antonio. Pedro Antonio. Error de compilación.

Dado el siguiente Stream indica las opciones que corresponden a cada fragmento de código aplicado: Stream<Personas> str3 = Stream.of(new Personas("Pedro", 23), new Personas("Juan", 17) , new Personas("Ana", 15), new Personas("Antonio", 23));. System.out.println(str3.collect(Collectors.averagingDouble(n->n.getEdad())));. System.out.println(str3.collect(Collectors.summingInt(n->n.getEdad())));. System.out.println(str3.map(n->" " + n.getEdad()).collect(Collectors.joining(", ")));.

Denunciar Test