Make the first letter caps and the rest lowercase in Java



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
Updated on: 2020-06-29T05:30:03+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements