Java String Capitalize capitalize(String string, int index)

Here you can find the source of capitalize(String string, int index)

Description

capitalize

License

Open Source License

Declaration

public static String capitalize(String string, int index) 

Method Source Code

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

public class Main {
    public static String capitalize(String string, int index) {
        if (index >= string.length() || index < 0) {
            throw new StringIndexOutOfBoundsException(index);
        }/*from   w  w w.jav a  2  s  . c  om*/

        final StringBuilder stringBuilder = new StringBuilder(string.length());

        if (index != 0) {
            stringBuilder.append(string, 0, index);
        }

        stringBuilder.append(Character.toUpperCase(string.charAt(index)));

        if (index != string.length() - 1) {
            stringBuilder.append(string.substring(index + 1));
        }

        return stringBuilder.toString();
    }
}

Related

  1. capitalize(String string)
  2. capitalize(String string)
  3. capitalize(String string)
  4. capitalize(String string)
  5. capitalize(String string, boolean firstWordOnly)
  6. capitalize(String string0)
  7. capitalize(String text)
  8. capitalize(String text)
  9. capitalize(String text)