Skip to content

Instantly share code, notes, and snippets.

@tedyoung
Created June 19, 2019 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedyoung/1df7401b453cb779a9b5ac2389df6baa to your computer and use it in GitHub Desktop.
Save tedyoung/1df7401b453cb779a9b5ac2389df6baa to your computer and use it in GitHub Desktop.
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