is String Title Case - Java java.lang

Java examples for java.lang:String Case

Description

is String Title Case

Demo Code

/***********************************************
 * Copyright to Vivek Kumar Singh * * Any part of code or file can be changed, *
 * redistributed, modified with the copyright * information intact * * Author$ :
 * Vivek Singh * */*from   w w  w  .j av  a2 s  .c  o m*/
 ***********************************************/
//package com.java2s;

public class Main {
    public static boolean isTitleCase(String s) {
        int strl = s.length();
        int i = 0;
        boolean titleActive = true;
        while (i < strl) {
            char nextC = s.charAt(i);
            if (titleActive == false) {
                if (Character.isTitleCase(nextC) == true
                        || Character.isUpperCase(nextC) == true)
                    return false;
            }
            if (titleActive == true || i == 0) {
                if (Character.isTitleCase(nextC) == false
                        && Character.isUpperCase(nextC) == false)
                    return false;
                titleActive = false;
            }
            if (Character.isWhitespace(nextC) == true)
                titleActive = true;
            i++;
        }
        return true;
    }

    public static boolean isUpperCase(String s) {
        int strl = s.length();
        int i = 0;
        while (i < strl) {
            char nextC = s.charAt(i);
            if (Character.isUpperCase(nextC) == false)
                return false;
            i++;
        }
        return true;
    }
}

Related Tutorials