Make the first letter caps and the rest lowercase in Java

Java 8Object Oriented ProgrammingProgramming

The following is an example −

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      String str = "laptop";
      System.out.println("Original String = " +str);
      // letter one
      String strOne = str.substring(0,1).toUpperCase();
      // remaining letters
      String strTwo = str.substring(1).toLowerCase();
      System.out.println("Resultant String = "+strOne + strTwo);
   }
}

Output

Original String = laptop
Resultant String = Laptop
raja
Published on 20-Dec-2018 12:36:25
Advertisements