String result = "Hello world."
.codePoints()
//.parallel() // uncomment this line for large strings
.map(c -> c == ' ' ? ' ': '*')
.collect(StringBuilder::new,
StringBuilder::appendCodePoint,
StringBuilder::append)
.toString();
But still, "Hello world.".replaceAll("[^ ]", "*")
is simpler. Not everything benefits from lambdas.
Related Contents:
- Java 8 Distinct by property
- Java 8 Iterable.forEach() vs foreach loop
- What is difference between Collection.stream().forEach() and Collection.forEach()?
- Filter Java Stream to 1 and only 1 element
- Using Java 8’s Optional with Stream::flatMap
- Java8: HashMap to HashMap using Stream / Map-Reduce / Collector
- Why does Iterable not provide stream() and parallelStream() methods?
- Using streams to convert a list of objects into a string obtained from the toString method
- How to use a Java8 lambda to sort a stream in reverse order?
- Java 8 stream’s .min() and .max(): why does this compile?
- What Java 8 Stream.collect equivalents are available in the standard Kotlin library?
- How to add elements of a Java8 stream into an existing List
- How to ensure order of processing in java8 streams?
- Can you split a stream into two streams?
- In Java 8 how do I transform a Map to another Map using a lambda?
- Get last element of Stream/List in a one-liner
- Java 8 functional interface with no arguments and no return value
- Difference between findAny() and findFirst() in Java 8
- Java 8, Streams to find the duplicate elements
- Multiple null checks in Java 8
- How do I keep the iteration order of a List when using Collections.toMap() on a stream?
- Java stream toArray() convert to a specific type of array
- Is it possible to use the Java 8 Stream API on Android API < 24?
- Modifying Objects within stream in Java8 while iterating
- Why does parallel stream with lambda in static initializer cause a deadlock?
- Java 8 Streams FlatMap method example
- How can I throw CHECKED exceptions from inside Java 8 lambdas/streams?
- Collectors.toMap() keyMapper — more succinct expression?
- Java 8 Collectors.toMap SortedMap
- Is there an elegant way to process a stream in chunks?
- Can I duplicate a Stream in Java 8?
- How to convert an Optional into a Stream?
- Null safe Collection as Stream in Java 8
- Java 8 stream map to list of keys sorted by values
- Stream of boolean values, is any true?
- How to check if exists any duplicate in Java 8 Streams?
- Java stream – Sort a List to a HashMap of Lists
- How do I get an IntStream from a List?
- In Java 8, is there a ByteStream class?
- A better approach to handling exceptions in a functional way
- Transform and filter a Java Map with streams
- Java 8 lambdas group list into map
- Merging two Map with Java 8 Stream API
- How to map to multiple elements with Java 8 streams?
- Parallel streams, collectors and thread safety
- When should I use IntStream.range in Java?
- How to force max to return ALL maximum values in a Java Stream?
- Does the JDK provide a dummy consumer?
- Is there a clean (and null safe) way to multiply the values of a map in Java?
- Java-8: boolean primitive array to stream?