Java Locale Format formatLines(String target, int maxLength, Locale currentLocale)

Here you can find the source of formatLines(String target, int maxLength, Locale currentLocale)

Description

Format lines.

License

Open Source License

Parameter

Parameter Description
target the target
maxLength the max length
currentLocale the current locale

Declaration

public static void formatLines(String target, int maxLength, Locale currentLocale) 

Method Source Code


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

Related

  1. formatingDecimalNumber(Object obj, Locale locale, int maxIntPart, int maxFloatPart)
  2. formatInt(final int number)
  3. formatInteger(int input)
  4. formatInteger(Long num)
  5. formatIntWithCommas(int num)
  6. formatLocaleDate(final java.util.Date date)
  7. formatLocaleTime(long time, Locale locale)
  8. formatMailDate(Date date)
  9. formatMessage(@Nonnull ResourceBundle bundle, @Nonnull String messageKey, @Nullable Object... args)