以下是一个例子-
public class Demo { public static void main(String[] args) { String str = "laptop"; System.out.println("Original String = " +str); //字母一 String strOne = str.substring(0,1).toUpperCase(); //剩余字母 String strTwo = str.substring(1).toLowerCase(); System.out.println("Resultant String = "+strOne + strTwo); } }
输出结果
Original String = laptop Resultant String = Laptop