java中怎样把字符串小写转化为大写

如有个String s="wangxu";
该怎样把它转化为大写;

第1个回答  2015-12-05

String的toUpperCase()方法

Java String.toUpperCase(Locale locale)方法用法实例教程,将在此字符串中的所有字符为大写的规则给定的Locale

package com.yiibai;

import java.lang.*;
import java.util.*;

public class StringDemo {

  public static void main(String[] args) {
  
    String str1 = "This is TutorialsPoint";

    // using the default system Locale
    Locale defloc = Locale.getDefault();
        
    // converts all lower case letters in to upper case letters
    System.out.println("string value = " + str1.toUpperCase(defloc));
    
    str1 = "www.baidu.com";
    System.out.println("string value = " + str1.toUpperCase(defloc));
  }
}

让我们来编译和运行上面的程序,这将产生以下结果:

string value = THIS IS TUTORIALSPOINT
string value = WWW.BAIDU.COM

第2个回答  2007-05-26
s = s.toUpperCase();本回答被提问者采纳
相似回答