to Capital Case with space separator - Android java.lang

Android examples for java.lang:String Case

Description

to Capital Case with space separator

Demo Code

import android.util.Base64;
import android.util.Log;
import android.util.Patterns;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.regex.Pattern;

public class Main{

    public static String toCapitalCase(String __text) {
      boolean afterWhiteSpace = true;
      char[] chars = __text.toLowerCase().toCharArray();
      for (int i = 0; i < chars.length; i++) {
         if (Character.isLetter(chars[i])) {
            if (afterWhiteSpace) {
               chars[i] = Character.toUpperCase(chars[i]);
               afterWhiteSpace = false;//from  w  w  w  .j a va 2  s  . c o m
            }
         } else {
            afterWhiteSpace = Character.isWhitespace(chars[i]);
         }
      }
      return new String(chars);
   }

}

Related Tutorials