39 lines
812 B
Java
39 lines
812 B
Java
|
// understandingcollections/FunctionalMap.java
|
||
|
// (c)2016 MindView LLC: see Copyright.txt
|
||
|
// We make no guarantees that this code is fit for any purpose.
|
||
|
// Visit http://OnJava8.com for more book information.
|
||
|
// Functional operations on a Map
|
||
|
import java.util.*;
|
||
|
import java.util.stream.*;
|
||
|
import java.util.concurrent.*;
|
||
|
import static onjava.HTMLColors.*;
|
||
|
|
||
|
public class FunctionalMap {
|
||
|
public static void main(String[] args) {
|
||
|
MAP.entrySet().stream()
|
||
|
.map(Map.Entry::getValue)
|
||
|
.filter(v -> v.startsWith("Dark"))
|
||
|
.map(v -> v.replaceFirst("Dark", "Hot"))
|
||
|
.forEach(System.out::println);
|
||
|
}
|
||
|
}
|
||
|
/* Output:
|
||
|
HotBlue
|
||
|
HotCyan
|
||
|
HotGoldenRod
|
||
|
HotGray
|
||
|
HotGreen
|
||
|
HotKhaki
|
||
|
HotMagenta
|
||
|
HotOliveGreen
|
||
|
HotOrange
|
||
|
HotOrchid
|
||
|
HotRed
|
||
|
HotSalmon
|
||
|
HotSeaGreen
|
||
|
HotSlateBlue
|
||
|
HotSlateGray
|
||
|
HotTurquoise
|
||
|
HotViolet
|
||
|
*/
|