Java String Split splitParagraphs(String value)

Here you can find the source of splitParagraphs(String value)

Description

Processes a doc comment into paragraphs.

License

Open Source License

Parameter

Parameter Description
value input value

Return

output paragraphs

Declaration

public static String[] splitParagraphs(String value) 

Method Source Code

//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()]);
    }
}

Related

  1. splitOnTokens(String text)
  2. splitOnTokens(String text)
  3. splitOrderedDurationsIntoIntervals(String[] durations, int numberOfIntervals)
  4. splitPackageName(String packageName)
  5. splitPackages(String packages)
  6. splitParameters(String parameters)
  7. splitParameters(String parameterString)
  8. splitParameterString(String theInput, boolean theUnescapeComponents)
  9. splitPartitionColStats(String key)