1. import java.util.List;
  2. import java.util.ArrayList;
  3. public class TextBlockPrinter {
  4. public static void printTextBlocks(List<String> textBlocks) {
  5. if (textBlocks == null || textBlocks.isEmpty()) {
  6. System.out.println("No text blocks to print.");
  7. return;
  8. }
  9. for (int i = 0; i < textBlocks.size(); i++) {
  10. String textBlock = textBlocks.get(i);
  11. System.out.println("--- Text Block " + (i + 1) + " ---");
  12. System.out.println(textBlock);
  13. System.out.println("--------------------------");
  14. }
  15. }
  16. public static void main(String[] args) {
  17. // Example usage
  18. List<String> blocks = new ArrayList<>();
  19. blocks.add("This is the first text block.\nIt contains multiple lines.");
  20. blocks.add("Here's the second block.\nIt's shorter.");
  21. blocks.add("A longer text block to demonstrate the printing.");
  22. printTextBlocks(blocks);
  23. }
  24. }

Add your comment