Solved

String Manipulation

Posted on 2004-04-08
4
294 Views
Last Modified: 2010-03-31
is there a way to take the first character of a string and change that character to upper case?

ex: word     needs to be changed to:    Word

thanks for the help
0
Comment
Question by:Orlando15767
  • 3
4 Comments
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 75 total points
ID: 10786934
String capitalized = original.substring(0,1).toUpperCase() + original.substring(1);
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10787003
or you can use this ("original" is your original String):

String capitalized = Character.toUpperCase(original.charAt(0)) + original.substring(1);
0
 
LVL 1

Author Comment

by:Orlando15767
ID: 10787029
perfect.
thanks for the help
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10787143
:°)
You are welcome.
Actually you might want to use this instead, it should be more efficient (event if it's a little more code):

    StringBuffer sbuff = new StringBuffer(original);
    sbuff.setCharAt(0, Character.toUpperCase(sbuff.charAt(0)));
    String capitalized = sbuff.toString();
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now