How to capitalize the first letter of word in a string using Java?

前端 未结 25 1517
抹茶落季
抹茶落季 2020-11-27 09:50

Example strings

one thousand only
two hundred
twenty
seven

How do I change the first character of a string in capital letter and not change

25条回答
  •  被撕碎了的回忆
    2020-11-27 10:45

    Example using StringTokenizer class :

    String st = "  hello all students";
    String st1;
    char f;
    String fs="";
    StringTokenizer a= new StringTokenizer(st);
    while(a.hasMoreTokens()){   
            st1=a.nextToken();
            f=Character.toUpperCase(st1.charAt(0));
            fs+=f+ st1.substring(1);
            System.out.println(fs);
    } 
    

提交回复
热议问题