java的String和StringBuilder方法
2021-06-16 13:06
标签:位置 string har system 插入 put bll nihao substr String s1="hello lxx"; 运行结果 9 Scanner input=new Scanner(System.in); 运行结果 gggdfgh java的String和StringBuilder方法 标签:位置 string har system 插入 put bll nihao substr 原文地址:https://www.cnblogs.com/1234cn/p/9726154.html
String s2=new String("fff df");
System.out.println(s1.length());
System.out.println(s1.substring(0, 2));
System.out.println(s1.equals(s2));
System.out.println(s1.charAt(3));
System.out.println(s1.replace("o","r"));
System.out.println(s1.indexOf("l"));
StringBuilder s3=new StringBuilder("hello nihao");
System.out.println(s3.append("a"));
// 打印s3的容量capacity()
System.out.println(s3.capacity());
//在2的位置插入b字符串
System.out.println(s3.insert(2, "b"));
System.out.println(s3.delete(2, 3));
//reverse反转
System.out.println(s3.reverse());
he
false
l
hellr lxx
2
hello nihaoa
27
hebllo nihaoa
hello nihaoa
aoahin olleh
StringBuilder s1=new StringBuilder( input.nextLine());
System.out.println(s1.reverse());
Scanner s2=new Scanner(System.in);
System.out.println("请输入字符串:");
String str=s2.nextLine();
String reverse = "";
for(int i=str.length()-1;i>=0;i--){
reverse+=str.charAt(i);
}
System.out.println(reverse);
hgfdggg
请输入字符串:
gbhnf
fnhbg
下一篇:R语言学习——条件筛选
文章标题:java的String和StringBuilder方法
文章链接:http://soscw.com/index.php/essay/94587.html