Java implements an example of converting the first letter of a string to uppercase and all other methods to lowercase

Time:2019-8-7

This article illustrates how Java implements the conversion of the first letter of a string to uppercase and all other methods to lower case. Share for your reference, as follows:

public class TestSubstring {
  public static void main(String[] args) {
    String s = getConvert("adsJKJ3K21AfaAD134F13241d134134s141faAAFDF");
    System.out.println(s);
  }
  // Convert the first letter of a string to uppercase, and all the rest to lowercase.
  public static String getConvert(String str) {
    String first = str.substring(0, 1);
    String after = str. substring (1); //substring (1) to get all the remaining strings after index position 1
    first = first.toUpperCase();
    after = after.toLowerCase();
    Return "converted string:" + first + after; //Adsjkj3k21afaad134f13241d134s141faaafdf
  }
}

Operation results:

PS: Here are some related online tools for your reference.

Online alphabet-case conversion tool:
http://tools.jb51.net/transcoding/upper

Online Chinese Pinyin Contrast Conversion Tool:
http://tools.jb51.net/transcoding/zh_pinyin

Online Chinese-English alphabetical sorting tool:
http://tools.jb51.net/aideddesign/zh_paixu

Readers interested in more about Java algorithms can see the topics on this site: Java Data Structure and Algorithms Tutorial, Summary of Java Operating DOM Node Skills, Summary of Java File and Directory Operating Skills, and Summary of Java Caching Operating Skills.

I hope this article will be helpful to the design of Java program.

Recommended Today

Monkey patch monkey patch programming method and its application in Ruby

What ismonkey patch (Monkey Patch)? In a dynamic language, functions are added and changed without modifying the source code. Purpose of using monkey patch:1. Additional function2. Function change3. Fix program errors4. Add a hook to execute some other processing while executing a method, such as printing logs, realizing AOP, etc,5. Cache, when the amount of […]