How to convert Name in Camel case From Java?

There are following way to convert Name in Camel case From java.

  • First we create a method getCamelCaseName and pass two String parameter FirstName and LastName.
  • Declare a string type variable FullName to store Camel Case name.
  • Inside first if condition we fetch first lastName word from lastName.substring(0, 1) method and convert to upperCase from toUpperCase() method.
  • Inside second if condition we fetch first firstName word from firstName.substring(0, 1) method and convert to upperCase from toUpperCase() method.
  • Now add the Camel Case (firstName , lastName) and store in fullName.
				
					public class ConvertName {
	private static String getCamelCaseName(String firstName, String lastName) {
		String fullName = "";
		if (null != lastName) {
			lastName = lastName.substring(0, 1).toUpperCase() + lastName.substring(1);
			if (null != firstName) {
				firstName = firstName.substring(0, 1).toUpperCase() + firstName.substring(1);
				fullName = lastName + ", " + firstName;
			}
		}

		return fullName;
	}

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

Output :-
My full Name is :- Kumar, Ajay