Puts all chars in the StringBuffer in lower case. - Java java.lang

Java examples for java.lang:StringBuffer

Description

Puts all chars in the StringBuffer in lower case.

Demo Code

/*  Copyright 2011 Alexander Bunkenburg alex@inspiracio.com

    This file is part of atom.jar./* w  w w  .  j  a  v a  2 s  .  c  o  m*/

    atom.jar is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    atom.jar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with atom.jar.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        StringBuffer buffer = new StringBuffer();
        toLowerCase(buffer);
    }

    /** Puts all chars in the buffer in lower case.
     * Does not allocate Strings, does not change the size of the
     * buffer.
     * @param buffer to be put into lower case */
    public static void toLowerCase(StringBuffer buffer) {
        final int N = buffer.length();
        for (int i = 0; i < N; i++) {
            char c = buffer.charAt(i);
            if (Character.isUpperCase(c)) {
                c = Character.toLowerCase(c);
                buffer.setCharAt(i, c);
            }
        }
    }
}

Related Tutorials