Here you can find the source of splitParagraphs(String value)
Parameter | Description |
---|---|
value | input value |
public static String[] splitParagraphs(String value)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /**// w w w .ja v a2 s .co m * Processes a doc comment into paragraphs. * * @param value input value * @return output paragraphs */ public static String[] splitParagraphs(String value) { String[] lines = split(value, '\n'); for (int i = 0; i < lines.length; i++) { lines[i] = lines[i].trim(); } ArrayList<String> output = new ArrayList<>(); StringBuilder current = new StringBuilder(); for (String line : lines) { if (line.length() == 0) { if (current.length() > 0) { output.add(current.toString()); current = new StringBuilder(); } } else { current.append(' ').append(line); } } if (current.length() > 0) { output.add(current.toString()); } return output.toArray(new String[output.size()]); } /** * Splits a string in parts, given a specified delimiter. * * @param value string to be split * @param delimiter delimiter * @return */ public static String[] split(String value, char delimiter) { if (value == null) return null; ArrayList<String> result = new ArrayList<>(); int start = 0; for (int i = 0; i < value.length(); i++) { if (value.charAt(i) == delimiter) { result.add(value.substring(start, i)); start = i + 1; } } result.add(value.substring(start)); return result.toArray(new String[result.size()]); } }