Created
June 19, 2019 00:45
-
-
Save tedyoung/1df7401b453cb779a9b5ac2389df6baa to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.List; | |
import java.util.Scanner; | |
import java.util.stream.Collectors; | |
class BlockTokens { | |
public static void main(String[] args) { | |
String text = "Block one.\n" + | |
"Still part of block one.\n" + | |
"Yep, still part of block one.\n" + | |
"\n" + | |
"Block two here.\n" + | |
"Still part of block two.\n" + | |
"\n" + | |
"Last block here.\n"; | |
Scanner scanner = new Scanner(text).useDelimiter("\n\n"); | |
List<String> paragraphs = scanner.tokens() | |
.map(s -> "<p>" + s + "</p>\n") | |
.collect(Collectors.toList()); | |
paragraphs.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment