Capitalize Strings in Java

public class StringManipulator {
    static String capitalize(String s) {
        return s.substring(0, 1).toUpperCase() + s.substring(1);
    }
    public static void main(String args[]) {
        String str = "good"
        System.out.println(capitalize(str));
        // prints out: Good
    }
}

In Ruby

str = "good"
puts str.capitalize
# prints out: Good

Easy isn’t it?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s