Java Char Upper Case toUpperCase(Object object)

Here you can find the source of toUpperCase(Object object)

Description

Attempts to convert an object to an uppercase string.

License

Apache License

Declaration

public static Object toUpperCase(Object object) 

Method Source Code

//package com.java2s;
/*****************************************************************
 *   Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License./*from w w w. j  a va2 s  .c om*/
 ****************************************************************/

public class Main {
    /**
     * Attempts to convert an object to an uppercase string.
     */
    public static Object toUpperCase(Object object) {
        if ((object instanceof String) || (object instanceof StringBuffer)) {
            return object.toString().toUpperCase();
        } else if (object instanceof char[]) {
            return new String((char[]) object).toUpperCase();
        } else {
            return object;
        }
    }

    /**
     * Attempts to convert an object to Comparable instance.
     */
    public static String toString(Object object) {
        if (object == null) {
            return null;
        } else if (object instanceof String) {
            return (String) object;
        } else if (object instanceof StringBuffer) {
            return object.toString();
        } else if (object instanceof char[]) {
            return new String((char[]) object);
        } else {
            throw new ClassCastException("Invalid class for String conversion:" + object.getClass().getName());
        }
    }
}

Related

  1. toUpperCase(char ch)
  2. toUpperCase(char input)
  3. toUpperCase(char[] cs)
  4. toUpperCase(final byte b)
  5. toUpperCase(final char[] buffer, final int offset, final int limit)
  6. toUppercaseHex(final int halfbyte)
  7. toUppercaseHexString(final char c)