Here you can find the source of capitalizeString(String text, boolean replaceUnderscore)
Parameter | Description |
---|---|
text | the text fixing. |
replaceUnderscore | True to replace all _ with a space, false otherwise. |
public static String capitalizeString(String text, boolean replaceUnderscore)
//package com.java2s; //License from project: Open Source License public class Main { /**/* www. java 2 s . c om*/ * Fix the given text with making the first letter captializsed and the rest not. * * @param text the text fixing. * @param replaceUnderscore True to replace all _ with a space, false otherwise. * @return The new fixed text. */ public static String capitalizeString(String text, boolean replaceUnderscore) { if (text.isEmpty()) { return text; } if (text.length() == 1) { return text.toUpperCase(); } String toReturn = text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase(); if (replaceUnderscore) { toReturn = toReturn.replace("_", " "); } return toReturn; } }