Powered by Blogger.

Display first fetter of a word with Capital letter in a given Sentence or String

>> Friday, February 28, 2020

The below code will display every first letter of a word in the sentence will display as a capital letter or in Camel Case using java program.
CamelCase Words in the Sentence


package com.javabynataraj.strings;

public class StringSpace {
 public static void main(String[] args) {
  String input = "HE IS A GOOD BOY";
  StringBuilder sb = new StringBuilder();
  for( String oneString : input.toLowerCase().split(" ") )
  {
      sb.append( oneString.substring(0,1).toUpperCase() );
      sb.append( oneString.substring(1)+" " );
  }
  System.out.println("Output--> "+sb);
 }
}

Output:
Output--> He Is A Good Boy 

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.