package class01.object01;
/**
*
* @create 2021-02-24 14:22
*/
public class Homework {
public static void main(String[] args) {
String str="this is a text";
//单独获取str中的单词
String[] arr = str.split(" ");
for (String string:arr
) {
System.out.println(string);
}
//将str中的text替换为practice
System.out.println(str.replace("text","practice"));
//在text前插入一个easy
System.out.println(str.replace("text","easy txet"));
//将每个单词的首写字母改为大写 toUpperCase() replace
for (int i =0;i<arr.length;i++
) {
char first=arr[i].charAt(0);
//把第一个字符转成大写
char upperfirst=Character.toUpperCase(first);
String news=upperfirst+arr[i].substring(1);
System.out.println(news);
}
}
}
一般的な文字列メソッドの演習
おすすめ
転載: blog.csdn.net/qq_43021902/article/details/114022656
おすすめ
ランキング