Java - Write code to convert first Char Upper Case using StringBuffer

Requirements

Write code to convert first Char Upper Case

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(firstCharUpperCase(str));
    }/* w w w  .j a  v a  2s  .co  m*/

    public static String firstCharUpperCase(String str) {
        StringBuffer buffer = new StringBuffer(str);
        if (buffer.length() > 0) {
            char c = buffer.charAt(0);
            buffer.setCharAt(0, Character.toUpperCase(c));
        }
        return buffer.toString();
    }
}

Related Exercise