Make Selenium Easy

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

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.