This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> ss = ...; | |
List<String> result = ...; | |
Stream<String> stream = ss.stream(); | |
stream.map(s -> { | |
synchronized (result) { | |
if (result.size() < 10) { | |
result.add(s); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Block> blocks = /* ... */; | |
int sumOfWeights = 0; | |
for (Block block : blocks) { | |
if (block.getColor() == Color.RED) { | |
sumOfWeights += block.getWeight(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Block> blocks = /* ... */; | |
int sumOfWeights = blocks.stream() | |
.filter(b -> b.getColor() == Color.RED) | |
.map(b -> b.getWeight()) | |
.sum(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.util.function.BiFunction<String, String, String> concat | |
= new java.util.function.BiFunction<String, String, String>() { | |
@Override | |
public String apply(String t, String u) { | |
return t + u; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MethodReferences { | |
public void f() { } | |
public void g() { | |
Runnable r = this::f; | |
r.run(); // f() is called. | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> ss = new ArrayList<>(); | |
ss.add("x,y,z"); | |
ss.add("x.y.z"); | |
ss.add("a,b,c"); | |
ss.add("i,j,k"); | |
String result = ss.stream() | |
.map(s -> s.replace(",", ".")) | |
.filter(s -> !s.contains("b")) | |
.distinct() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hartveld.examples; | |
import static org.mockito.Mockito.verify; | |
import static org.mockito.Mockito.verifyNoMoreInteractions; | |
import java.util.function.Consumer; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mock; | |
import org.mockito.runners.MockitoJUnitRunner; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hartveld.examples; | |
import java.util.function.Consumer; | |
import java.util.function.Function; | |
import java.util.function.Predicate; | |
public interface Observable<T> { | |
void subscribe(Consumer<T> onNext); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface java.lang.Iterable<T> { | |
abstract Iterator<T> iterator(); | |
default void forEach(Consumer<? super T> consumer) { | |
for (T t : this) { | |
consumer.accept(t); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.util.function.BiFunction<String, String, String> concat1 | |
= (String s, String t) -> { | |
return s + t; | |
}; | |
java.util.function.BiFunction<String, String, String> concat2 | |
= (s, t) -> s + t; |
NewerOlder