Java String Capitalize capitalize(final String str, final char... delimiters)

Here you can find the source of capitalize(final String str, final char... delimiters)

Description

capitalize

License

Open Source License

Declaration

public static String capitalize(final String str, final char... delimiters) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String capitalize(final String str, final char... delimiters) {
        final int delimLen = delimiters == null ? -1 : delimiters.length;
        if (isEmpty(str) || delimLen == 0) {
            return str;
        }//from ww  w. j  a v a2  s .c  o m
        final char[] buffer = str.toCharArray();
        boolean capitalizeNext = true;
        for (int i = 0; i < buffer.length; i++) {
            final char ch = buffer[i];
            if (isDelimiter(ch, delimiters)) {
                capitalizeNext = true;
            } else if (capitalizeNext) {
                buffer[i] = Character.toTitleCase(ch);
                capitalizeNext = false;
            }
        }
        return new String(buffer);
    }

    public static boolean isEmpty(final CharSequence cs) {
        return cs == null || cs.length() == 0;
    }

    private static boolean isDelimiter(final char ch, final char[] delimiters) {
        if (delimiters == null) {
            return Character.isWhitespace(ch);
        }
        for (final char delimiter : delimiters) {
            if (ch == delimiter) {
                return true;
            }
        }
        return false;
    }
}

Related

  1. capitalize(final String str)
  2. capitalize(final String str)
  3. capitalize(final String str)
  4. capitalize(final String str)
  5. capitalize(final String str)
  6. capitalize(final String text)
  7. capitalize(final String value)
  8. capitalize(final String value)
  9. capitalize(final String value)