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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 29-Jun-2020

658 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements