Java String Capitalize capitalize(String s, String fullstring)

Here you can find the source of capitalize(String s, String fullstring)

Description

capitalize

License

Open Source License

Declaration

public static String capitalize(String s, String fullstring) 

Method Source Code

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

public class Main {
    public static String capitalize(String s, String fullstring) {
        s = s.trim();//from  w  ww.  j a  v a 2  s  .co  m

        if (fullstring == null || fullstring.isEmpty()) {
            fullstring = s;
        }

        if (fullstring.length() < 3) {
            return s.toUpperCase();
        }

        if (s.contains(" ")) {
            StringBuilder ret = new StringBuilder();

            for (String a : s.split(" ")) {
                ret.append(" ").append(capitalize(a, s));
            }

            return ret.toString();
        } else {
            if (s.contains(".")) {
                StringBuilder t = new StringBuilder();

                for (String b : s.split("\\.")) {
                    t.append(".").append(capitalize(b, s));
                }

                return t.substring(1);
            } else {
                return Character.toUpperCase(s.charAt(0)) + s.substring(1).toLowerCase();
            }
        }
    }
}

Related

  1. capitalize(String s)
  2. capitalize(String s)
  3. capitalize(String s)
  4. capitalize(String s)
  5. capitalize(String s, char delimiter)
  6. capitalize(String source)
  7. capitalize(String src)
  8. capitalize(String str)
  9. capitalize(String str)