Java - Write code to Convert string to Upper Case using StringBuffer

Requirements

Write code to convert string to Upper Case

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(toUpperCase(str));
    }//from  w  w  w .ja  v a2 s  . co m

    public static String toUpperCase(String str) {
        StringBuffer buffer = new StringBuffer(str);
        for (int i = 0; i < buffer.length(); i++) {
            char c = buffer.charAt(i);
            buffer.setCharAt(i, Character.toUpperCase(c));
        }
        return buffer.toString();
    }
}

Related Exercise