Hey everyone,

I'm new at this.. so please bear with me.

Anyway, I'm really confused.

I'm supposed to convert the first character of the String firstName to upper case.

Problem is... I have no idea how to :-/

I've done so much research and reading and still nothing.

Please help me.

Thanks in advance!

This is my code;

public class Main {

     * @param args the command line arguments
    public static void main(String[] args) {

        char firstSymbol;

        // First and Last Name

        String firstName="mickey";
        String lastName="mouse";
        System.out.println(lastName + "," + firstName);

Edited by pyTony: fixed formatting

9 Years
Discussion Span
Last Post by webmstr

Thank you for your reply.
I figured out how to do it using the replace method. However, now I'm asked to do it using the variable firstSymbol.


Well if you use the replace method you will have to hard code your code. Which is ok if you know what the string variable contains, In a case where you don't know, this will not be good. So It is probably good if you get familiar with the toUpperCase method in the Character class.

Here is an example how to use it:

String unknown = " java";

//charAt gets the first character in string and upperCase converts it to uppercase	
//then I add the uppercase J to the rest of the String with substring starting at the second
//character in the string java, so basically:  J + ava -> Java	

unknown = Character.toUpperCase(unknown.charAt(0)) + unknown.substring(1);

Thank you! Works great, But does it incorporate the firstSymbol variable I told you about? =/


Have you heard of unicode? In unicode each character has a corresponding number. A-Z corresponds with 65-90, while a-z corresponds with 97-122. In order to make the letter j into a capitol J you would convert the j into unicode, subtract 22, and convert back to letters, but I don't remember how to do it and I forgot to write it down in my notes LOL so just search around for unicode and it should help you.

PS I am a student and I just learned about this last week so if I'm wrong please feel free to correct me... I am trying to solve my own problems and thought I'd look around and see what else was here lol


Hi guys, converting uppercase or lowercase strings in java is so simple but if you wanna see a more complex application you can look at here...

There is a function that makes first letters of words, sentences or lines Uppercased in JAVA.
<URL SNIPPED>Uppercasing First Letters

This may be useful for learning more string operations.

Edited by peter_budo: Keep It On The Site - Posts must contain actual content and substance and cannot simply be external links.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.