DEV Community

Saravanan Muniraj
Saravanan Muniraj

Posted on

Convert all the first letters in a statement to capital letters

To convert all the first letters in a statement to capital letters, you can achieve this by checking if the addresses stored in the database are all in lowercase and then display them with the first letter capitalized using Java.

private static String capitalizeFirst(String word) {
    return word.substring(0, 1).toUpperCase()
      + word.substring(1).toLowerCase();
}


public static String capitalizeAllFirstLetters(String address){

    Pattern pattern = Pattern.compile("^[A-Z,a-z]");
    String[] addressArray = address.split(" ");
    StringBuffer afterChangesAddress = new StringBuffer();

    for(int i=0;i<addressArray.length;i++){
         Matcher m = pattern.matcher(addressArray[i]);
          if(m.find()){
              afterChangesAddress.append(capitalizeFirst(addressArray[i])).append(" ");
         }else{
             afterChangesAddress.append(addressArray[i]).append(" ");
         }
    }
    return afterChangesAddress.substring(0, afterChangesAddress.lastIndexOf(" "));

 }




public static void main(String[] args) {


    String str = capitalizeAllFirstLetters("1180 seven seats dr, orlando, fl 3283");

    System.out.println(str);

}
Enter fullscreen mode Exit fullscreen mode

Output:
1180 Seven Seats Dr, Orlando, Fl 3283

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay