Java String Title Case toTitleCase(String s)

Here you can find the source of toTitleCase(String s)

Description

to Title Case

License

Open Source License

Declaration

public static String toTitleCase(String s) 

Method Source Code

//package com.java2s;

public class Main {
    public static String toTitleCase(String s) {
        s = s.toLowerCase();//from   w  ww .  j  ava2 s.c om
        int strl = s.length();
        char[] holder = new char[strl];
        boolean titleActive = true;

        int i = 0;
        while (i < strl) {
            char nextC = s.charAt(i);
            if (titleActive == true || i == 0) {
                nextC = Character.toTitleCase(nextC);
                titleActive = false;
            }
            if (Character.isWhitespace(nextC) == true)
                titleActive = true;

            holder[i] = nextC;
            i++;
        }

        return new String(holder);

    }

    public static String toLowerCase(String s) {
        return s.toLowerCase();
    }
}

Related

  1. toTitleCase(String inputStr)
  2. toTitleCase(String name)
  3. toTitleCase(String original)
  4. toTitleCase(String original)
  5. toTitleCase(String s)
  6. toTitleCase(String sIn)
  7. toTitleCase(String str)
  8. toTitleCase(String str)
  9. toTitleCase(String string)