Set<Person> owners = new HashSet<>();
for (Car c : cars) {
owners.add(c.getOwner());
}
x → x+1
.→
, např.Person
.Set<Person> owners = new HashSet<>();
for (Car c : cars) {
owners.add(c.getOwner());
}
owners = cars.stream()
.map(Car::getOwner)
.collect(Collectors.toSet());
Kód Car::getOwner
je zkráceně x → x.getOwner()
.
Set<Person> owners = new HashSet<>();
for (Car c : cars) {
if (c.hasExpiredTicket()) owners.add(c.getOwner());
}
Nebo:
owners = cars.stream()
.filter(c -> c.hasExpiredTicket())
.map(Car::getOwner)
.collect(Collectors.toSet());
null
prvků?return cars.stream()
.filter(c -> c != null)
.collect(Collectors.toList());
null
prvků?IntStream.range(0, cars.size())
.filter(i -> cars.get(i) == null)
.boxed()
.collect(Collectors.toList());
většinou jako generická (typově parametrizovaná) rozhraní, např.:
s jednou metodou boolean test(T t)
s jednou metodou void get(T t)
s jednou metodou void accept(T t)
/