将第一个字母大写

时间:2016-04-19 10:58:01

标签: android

我很困惑为什么我的代码没有大写我的第一个字母,我从数据库中得到用户的名字,所有字母都是小写的。

这是代码:

    String email = null;
    String name = null;
    StringBuilder nameSB = new StringBuilder();
    nameSB.append(name);
    nameSB.setCharAt(0, Character.toUpperCase(nameSB.charAt(0)));
    name = nameSB.toString();

    try {
        email = ((User) ParseUser.getCurrentUser()).getEmail();
        name = ((User) ParseUser.getCurrentUser()).getFirstName() + " " + ((User) ParseUser.getCurrentUser()).getLastName();

    } catch (NullPointerException npe) {
    }

1 个答案:

答案 0 :(得分:0)

只是总结为答案

String email = null;
String name = null;
StringBuilder nameSB = new StringBuilder();

try {
    email = ((User) ParseUser.getCurrentUser()).getEmail();
    name = ((User) ParseUser.getCurrentUser()).getFirstName() + " " + ((User) ParseUser.getCurrentUser()).getLastName();

    nameSB.append(name);
    nameSB.setCharAt(0, Character.toUpperCase(nameSB.charAt(0)));
    name = nameSB.toString();

} catch (NullPointerException npe) {
}