Java String Capitalize capitalize(String string)

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

Description

capitalize

License

Apache License

Declaration

private static String capitalize(String string) 

Method Source Code

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

public class Main {
    private static String capitalize(String string) {
        if (isEmptyTrim(string)) {
            return string;
        }//from   w  w w. jav  a 2  s.com
        if (string.length() < 2) {
            return string.toUpperCase();
        }
        return Character.toUpperCase(string.charAt(0)) + string.substring(1).toLowerCase();
    }

    public static boolean isEmptyTrim(String valore) {
        return (valore == null || valore.trim().equals(""));
    }

    /**
     * Restiutisce la stringa s senza spazi iniziali e finali
     * Se s e' null o stringa vuota, restituisce una stringa di lunghezza 0
     */
    public static String trim(String s) {
        return s == null || s.trim().equals("") ? "" : s.trim();
    }
}

Related

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