Converts the entire string into uppercase and lowercase letters, and returns the string in uppercase and lowercase letters.

Source: Internet
Author: User
Tags uppercase character

Converts the entire string into uppercase and lowercase letters, and returns the string in uppercase and lowercase letters.

Recently I used the uppercase Character function. The general idea is to use charAt (0) combined with Character's toUpperCase Method for conversion, and finally combine it into a string.

A few days ago, I saw a great god's code and thought it was highly efficient. If you are interested, please take a look.

The Code is as follows:

/*** Capitalized conversion * @ param str source String. Chinese characters * @ return */public static String firstCharUpper (String str) {if (str! = Null & Character. isLowerCase (str. charAt (0) {// determine whether it is in upper or lower case based on your needs. Modify char [] charArray = str. toCharArray (); if (charArray! = Null) {charArray [0]-= 32; // convert lowercase to uppercase. If it is lowercase to lowercase, It is + = 32. You need to judge return String above. valueOf (charArray) ;}} return str ;}

The following is a string that is similar to the upper-case string.

/*** Capitalized String * @ param str * @ return */public static String strUpperCase (String str) {if (str! = Null) {char [] charArray = str. toCharArray (); for (int I = 0; I <str. length (); I ++) {if (Character. isLowerCase (str. charAt (I) charArray [I]-= 32;} return String. valueOf (charArray);} return str;}/*** String lowercase * @ param str * @ return */public static String strLowerCase (String str) {if (str! = Null) {char [] charArray = str. toCharArray (); for (int I = 0; I <str. length (); I ++) {if (Character. isUpperCase (str. charAt (I) charArray [I] + = 32;} return String. valueOf (charArray);} return str ;}

For more information, see.

@ Ink

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.