Java字符串就是Unicode字符序列。Java没有内置的字符串类型,而是在标准Java类库中提供了一个预约义类String,位于java.lang包中,编译器会默认导入这个包。字符串被做为String类型的对象来处理。java
建立String对象的方法:ide
一、String s = "Hello World";code
二、String s = new String();对象
三、String s = new String("Hello World");索引
获取字符串的长度:字符串名。length();字符串
字符串比较:字符串1.equals(字符串2);//相同的字母,大小写不一样也是不相同编译器
字符串1.equalsIgnoreCase(字符串2);//比较时忽略大小写string
toLowerCase() 转换字符串中的英文字符为小写it
toUpperCase() 转换字符串中的英文字符为大写编译
字符串链接:
一、使用"+"运算符,
二、使用String类的concat()方法
字符串经常使用的提取和查询方法:
方法 说明
public int indexOf(int ch) 搜索第一个出现的字符ch
public int indexOf(String value) 搜索第一个出现的字符串value
public int lastIndexOf(int ch) 搜索最后一个出现的字符ch
public int lastIndexOf(String Value) 搜索最后一个出现的字符串value
public String substring (int index) 提取从位置索引开始的字符串部分
public String substring(int beginIndex, int endIndex); 提取beginIndex和endIndex之间的字符串部分
public String trim( ) 去除字符串的先后空格,并返回副本