Java String upper case

Description

Java String upper case


//package com.demo2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String text = "demo2s.com";
        System.out.println(allCaps(text));
    }//from w  w  w  .  j a v a2s  .  com

    /**
     * Format a string of text into the all capitals format.  
     * This means all characters are uppercase, and spaces are represented 
     * as underscores.<br>
     * This is the inverse of <code>upperFirst(text)</code>
     * @param text The text to format
     * @return A formatted string
     */
    public static String allCaps(String text) {
        String newText = text.replaceAll(" ", "_");
        newText = newText.toUpperCase();

        return newText;
    }
}



PreviousNext

Related