import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
List<List<Integer>> data = List.of(
List.of(1, 2),
List.of(3, 4)
);
List<Integer> result = data.stream()
.flatMap(List::stream)
.collect(Collectors.toList());
System.out.println(result);
}
}
❤1👍1
Что выведет код? 👆
Anonymous Quiz
27%
[[1, 2], [3, 4]]
5%
[1, 2]
60%
[1, 2, 3, 4]
7%
<Ошибка компиляции>
👍3❤1🎉1
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
Stream.of(1, 2, 3, 4)
.parallel()
.forEach(System.out::print);
}
}
❤1
❤1🎉1
public class Main {
public static void main(String[] args) {
String s = "hello";
System.out.println(s.getClass().getName());
}
}❤2
❤1🎉1
interface A {
default void print() { System.out.println("A"); }
}
interface B extends A {
default void print() { System.out.println("B"); }
}
class C implements B {
public static void main(String[] args) {
new C().print();
}
}❤1
❤1🎉1
class Base {
public String className = "Base";
public String getClassName() {
return className;
}
}
class Derived extends Base {
public String className = "Derived";
}
public class Test {
public static void main(String[] args) {
System.out.println(new Derived().getClassName());
}
}❤3
🎉2
public class Test {
public static void main(String[] args) {
int i = 5;
boolean b = bool(i++ * 2) && bool(i);
}
public static boolean bool(int i) {
System.out.print(i);
return true;
}
}❤4
import java.util.Objects;
class Person {
Long id;
String name;
public Person(Long id, String name) {
this.id = id;
this.name = name;
}
public boolean equals(Person other) {
if (other == this) {
return true;
}
return id != null && id.equals(other.id);
}
}
public class Test {
public static void main(String[] args) {
Person person1 = new Person(1L, "John");
Person person2 = new Person(1L, "Jane");
System.out.print(person1.equals(person2));
System.out.print("-");
System.out.print(Objects.equals(person1, person2));
}
}
❤1🔥1
🔥1🎉1
import java.util.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
Map<Boolean, List<Integer>> map =
IntStream.rangeClosed(1, 5)
.boxed()
.collect(Collectors.groupingBy(n -> n % 2 == 0));
System.out.println(map.get(false).size() + " " + map.get(true).size());
}
}
❤1
🎉1
public class Test {
{
System.out.println(i);
}
int i;
public Test(int i){
this.i = i;
}
public static void main(String[] args) {
new Test(1);
}
}❤3🔥1
🎉1
public class Test {
public static void main(String[] args) {
Short b = 50;
inc(b);
System.out.println(b);
}
private static void inc(Short num) {
num++;
}
}❤1🔥1
🎉1