Java - Write code to Capitalize the first letter in the passed string

Requirements

Write code to Capitalize the first letter in the passed string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String cs = "book2s.com";
        System.out.println(initCap(cs));
    }/*w w  w .  j  ava 2s .c o  m*/

    /**
     * Caps the first letter in the passed string
     * @param cs The string value to initcap
     * @return the initcapped string
     */
    public static String initCap(CharSequence cs) {
        char[] chars = cs.toString().trim().toCharArray();
        chars[0] = new String(new char[] { chars[0] }).toUpperCase()
                .charAt(0);
        return new String(chars);
    }
}

Related Exercise