public class StringDemo {
public static void main(String[] args){
String s="厚积薄发";//在内存中开辟一个空间
s="厚积薄发创未来!";
System.out.println(s);
String s1="lisi@163.com";
//获取致电该参数在当前字符串中索引位置,索引位置从0开始
int index=s1.indexOf("@");
System.out.println(index);
String fileContent="请输入上传文件名称";
//按照给定的开始和结束的索引位置对字符串进行截取
String file=fileContent.substring(5,8);
System.out.println(file);
String name="zhangsan";
System.out.println("我的名字叫"+name);
//contact()的处理方法是以String类型返回
//必须将处理结果重新赋值给指定的的变量
String str="我叫";
String str1="lisi";
str=str.concat(str1);
System.out.println(str);
String
str3="我们国家领导人是***,他是富平人";
//replace完成对字符串中指定内容的替换,可以替换所有相同的内容
str3=str3.replace("***", "***");
System.out.println(str3);
//取出空格,自能取出字符串前后的空格,无法去除字符串中间的
String str4=" a b c ";
System.out.println(str4.trim());
}
}
转载于:https://www.cnblogs.com/huangzhe1515023110/p/9276123.html