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));
    }/*from   w  ww .  j av a2s.  c  om*/

    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();
    }
}