convert First Char To Upper Case - Java java.lang

Java examples for java.lang:String Case

Introduction

The following code shows how to convert First Char To Upper Case.

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String term = "java2s.com";
        System.out.println(convertFirstCharToUpperCase(term));
    }//from   w  ww . ja va2 s.c  o  m

    public static String convertFirstCharToUpperCase(final String term) {
        String convertedString = null;
        char[] charsSeq = term.toCharArray();

        int hexChar = (int) charsSeq[0] - 0x20;
        if (hexChar < 0x41) {
            convertedString = term;
        } else {
            charsSeq[0] = (char) hexChar;
            convertedString = String.valueOf(charsSeq);
        }
        return convertedString;
    }
}

Related Tutorials