-2

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.

Little bird
  • 1,106
  • 7
  • 28
  • 58

2 Answers2

2

I am not gonna give you the code but you can achieve what you want using the steps below:

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 the String
  • 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