Suppose i have a string value i.e michael . What i need that i want the this value in the form of 'Michael' . What could be the better programming approach though i'm beginner of java. Any help will be highly appreciated.
Asked
Active
Viewed 710 times
-2
-
initialize your string as Michael??? – Kakalokia Mar 11 '13 at 16:06
-
Here is the greatest programming help tool ever created: google.com learn to use it and you will go far. – DwB Mar 11 '13 at 16:08
-
Thanx to everyone who have commented . Google is excellent engine but i wanted the best results from u all :) – Little bird Mar 11 '13 at 16:13
2 Answers
2
I am not gonna give you the code but you can achieve what you want using the steps below:
- Get the first charcter from the string using String#charAt(0)
- Use Character#toUpperCase to convert it into uppercase
- concatenate the result back to the original string

PermGenError
- 45,977
- 8
- 87
- 106
2
String str = "abcd";
Character first = Character.toUpperCase(str.charAt(0));
str = first + str.substring(1, str.length());
System.out.println(str); //Will print Abcd
This code
- Gets the first
Character
from theString
- Converts it to upper case (using
Character.toUpperCase(char ch)
) - Concatenate the first letter (that was changed to upper case) with the rest of the
String
I don't like to use the +
operator for concatenating strings, consider using concat
method (or StringBuilder in case you want to concatenate more strings..)

Maroun
- 94,125
- 30
- 188
- 241