Java - Write code to lowercase All characters in a string by checking ASCII code

Requirements

Write code to lowercase All characters in a string by checking ASCII code

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "Book2s.com";
        System.out.println(lowcaseAll(s));
    }//from w ww . j  a  v  a2s .c o m

    public static String lowcaseAll(String s) {
        if (s == null || s.equals("")) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        char[] c = s.toCharArray();
        for (int i = 0; i < c.length; i++) {
            if (c[i] < 97) {
                sb.append((c[i] + "").toLowerCase());
            } else {
                sb.append(c[i]);
            }
        }
        return sb.toString();
    }
}

Related Exercise