How to simulate the title function of Python [string.title ()] in Java?

2

In python, the string has a function called title, which causes a text to be like a title. Does it have such a function in Java? If not, how to do it?

Example: "Hi, my name is goku" .title () - > "Hi, My Name Is Goku"

I need this function because I'm working with people's names, and the person's name has to stay that way.

Another example: freterotilda astrobalda - > Freterotilda Astrobalda

    
asked by anonymous 24.08.2014 / 22:46

1 answer

2

The Apache Commons Lang library has the function capitalize in class WordUtils .

String title = WordUtils.capitalize("oi, meu nome é goku");

If you need to normalize a title beyond the first letter there is also the function capitalizeFully .

String title = WordUtils.capitalizeFully("oi, meu nOME é gOKU");

Source: SOen - Capitalize First Char of Each Word in a String Java

    
24.08.2014 / 23:00