Java Program to Convert a String Name in Camel Case.

There are following way to Convert a String Name in Camel Case.

  • First we create one metod getCamelCaseName() with two input parameter.
  • Inside if condition check firstName and lastName is not null.
  • from this lastName.substring(0, 1).toUpperCase() method find first character of lastName and convert in uppercase and lastName.substring(1) add remaining of String.
  • from this firstName.substring(0, 1).toUpperCase() method find first character of firstName and convert in uppercase and lastName.substring(1) add remaining of String.
  • Add lastName and firstName with comma separate to print as fullName in Camel Case.
public class CamelCaseName {
	private static String getCamelCaseName(String firstName, String lastName) {
		String fullName = "";
		if (null != lastName && null != firstName) {
			lastName = lastName.substring(0, 1).toUpperCase() + lastName.substring(1);
			firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1);
		}
		fullName = lastName + ", " + firstName;

		return fullName;
	}

	public static void main(String[] args) {
		System.out.println("Full Name is :- " + getCamelCaseName("Ajay", "kumar"));
	}
}

Output :-

Full Name is :- Kumar, Ajay

Java Program to Convert a String Name in Camel Case. Read More »