Here you can find the source of formatLines(String target, int maxLength, Locale currentLocale)
Parameter | Description |
---|---|
target | the target |
maxLength | the max length |
currentLocale | the current locale |
public static void formatLines(String target, int maxLength, Locale currentLocale)
//package com.java2s; //License from project: Open Source License import java.text.BreakIterator; import java.util.Locale; public class Main { /**// w w w . j a v a 2s. c om * Format lines. * * @param target the target * @param maxLength the max length * @param currentLocale the current locale */ public static void formatLines(String target, int maxLength, Locale currentLocale) { BreakIterator boundary = BreakIterator.getLineInstance(currentLocale); boundary.setText(target); int start = boundary.first(); int end = boundary.next(); int lineLength = 0; while (end != BreakIterator.DONE) { String word = target.substring(start, end); lineLength = lineLength + word.length(); if (lineLength >= maxLength) { System.out.println(); lineLength = word.length(); } System.out.print(word); start = end; end = boundary.next(); } } }