Frequently Asked Java Program 25: Java Program to Convert a String Sentence in Camel Case

“CamelCase” is a naming convention in which words are joined together without any whitespace in between and each word starts with a capital letter which increase readability. It is mostly used to name variables and methods in programming languages.

Example: MakeSeleniumEasy

Problem Statement:

Input:

make selenium easy

Output:

MakeSeleniumEasy

Convert first character of each word into upper case and join without any whitespace.

Solution:

Logic:

  1. A sentence is a collection of words generally separated by a white space. We can extract words of given sentence using split method.
  2.  Now extract first character of first word and check if it is not uppercase already. If it is not, convert first char to upper case and append remaining characters of word. we can use subString method. If it is already in uppercase, append entire word. Repeat the same for all words.

Java Program:

 

Output:

Please enter the string to convert in to camel case:
make selenium easy
You entered: make selenium easy
Output is :MakeSeleniumEasy
====================================================
Please enter the string to convert in to camel case:
MakeSeleniumEasy
You entered: MakeSeleniumEasy
Output is :MakeSeleniumEasy
===================================================
Please enter the string to convert in to camel case:
MakeSeleniumEasy
You entered: MakeSeleniumEasy
Output is :MakeSeleniumEasy
=====================================================

#HappyCoding

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning