Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8220283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:28:22+00:00 2026-06-07T13:28:22+00:00

Possible Duplicate: How to upper case every first letter of word in a string?

  • 0

Possible Duplicate:
How to upper case every first letter of word in a string?
Most efficient way to make the first character of a String lower case?

I want to convert the first letter of a string to upper case. I am attempting to use replaceFirst() as described in JavaDocs, but I have no idea what is meant by regular expression.

Here is the code I have tried so far:

public static String cap1stChar(String userIdea)
{
    String betterIdea, userIdeaUC;
    char char1;
    userIdeaUC = userIdea.toUpperCase();
    char1 = userIdeaUC.charAt(0);
    betterIdea = userIdea.replaceFirst(char1); 
    return betterIdea;
}//end cap1stChar

The compiler error is that the argument lists differ in lengths. I presume that is because the regex is missing, however I don’t know what that is exactly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:28:23+00:00Added an answer on June 7, 2026 at 1:28 pm

    Regular Expressions (abbreviated “regex” or “reg-ex”) is a string that defines a search pattern.

    What replaceFirst() does is it uses the regular expression provided in the parameters and replaces the first result from the search with whatever you pass in as the other parameter.

    What you want to do is convert the string to an array using the String class’ charAt() method, and then use Character.toUpperCase() to change the character to upper case (obviously). Your code would look like this:

    char first = Character.toUpperCase(userIdea.charAt(0));
    betterIdea = first + userIdea.substring(1);
    

    Or, if you feel comfortable with more complex, one-lined java code:

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

    Both of these do the same thing, which is converting the first character of userIdea to an upper case character.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Capitalize first letter of string in javascript How do I make the
Possible Duplicate: python random string generation with upper case letters and digits How do
Possible Duplicate: RegEx to make sure that the string contains at least one lower
Possible Duplicate: Convert a String In C++ To Upper Case Hi, I need a
Possible Duplicate: python random string generation with upper case letters and digits I need
Possible Duplicate: Is there a good reason to use upper case for T-SQL keywords?
Possible Duplicate: How to get random string with spaces and mixed case? How do
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way
Possible Duplicate: Converting string in C# I want to camelize a string, for example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.