Java String Capitalize capitalize(String in)

Here you can find the source of capitalize(String in)

Description

{ method

License

Apache License

Parameter

Parameter Description
in - string to capitalize

Return

- non-null capitailzed string }

Declaration

public static String capitalize(String in) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**{ method/*from w  w w.ja v a2  s .  c o m*/
     @name capitalize
     @function - test of the object test is a member of the list data
     @param in - string to capitalize
     @return  - non-null capitailzed string
     }*/
    public static String capitalize(String in) {
        if (in.length() == 0)
            return ("");
        StringBuffer s = new StringBuffer(in.length());
        int i = 0;
        char c = in.charAt(i++);
        while (c <= ' ') {
            c = in.charAt(i++);
            if (i >= in.length())
                return ("");
        }

        s.append(Character.toUpperCase(c));
        boolean atSpace = false;
        for (; i < in.length(); i++) {
            c = Character.toLowerCase(in.charAt(i));
            if (c == ' ') {
                atSpace = true;
            } else {
                if (atSpace) {
                    if (c > ' ') {
                        c = Character.toUpperCase(c);
                        atSpace = false;
                    }
                }
            }
            s.append(c);
        }
        return (s.toString());
    }

    /**{ method
     @name toString
     @function convert a char to a string
     @param c the char
     @return the String
     }*/
    public static String toString(char c) {
        StringBuffer s = new StringBuffer();
        s.append(c);
        return (s.toString());
    }
}

Related

  1. capitalize(String capitalizeMe)
  2. capitalize(String constraint)
  3. capitalize(String content)
  4. capitalize(String data)
  5. capitalize(String english)
  6. capitalize(String in)
  7. capitalize(String in)
  8. capitalize(String in)
  9. capitalize(String input)