How to Convert String to Initcap Using Java

 Posted On  | Yashwant Chavan | Views :- 6666

Sample code convert input string into init cap letter using java,First we convert the input string into char array. Then convert its first letter to Upper Case.

toInitCap() method

package com.net.technicalkeeda.sample;

public class InitCapExample {
	public static void main(String[] args) {
		System.out.println(toInitCap("yashwant"));
	}

	public static String toInitCap(String param) {
		if(param != null && param.length()>0){			
			char[] charArray = param.toCharArray(); // convert into char array
			charArray[0] = Character.toUpperCase(charArray[0]); // set capital letter to first postion
			return new String(charArray); // return desired output
		}else{
			return "";
		}
	}
}

Output

Yashwant

Tags Java 


HTML Comment Box is loading comments...

Hi I am Yashwant Chavan founder of www.technicalkeeda.com, Purpose of this website to share the programming knowledge in the form post , blogs and articles.

Latest Updates

Stay updated with latest post, articles and technical discussions.

Most Popular Articles



© technicalkeeda.com 2014