
Java String类
云淡风轻58
代码是程序员的朋友,虽然没有热情,但是非常忠实。扣:83475375
展开
-
字符串的声明
输出: str1=string str2=str str3=hello world原创 2017-12-15 08:31:41 · 1844 阅读 · 0 评论 -
获取字符串长度和字符串连接
获取字符串长度 str.length() str表示字符串对象 示例:获取字符串长度 public class Demo{ public static void main(String[] args){ //声明一个字符数组 char ch[]= {'s','t','r','i','n','g'}; String str=new String(ch); System.原创 2017-12-15 10:38:28 · 815 阅读 · 0 评论 -
查找、替换、子字符串
查找字符串 1. 查找指定索引位置的字符 String str="hello world"; char ch=str.charAt(6); //返回w 2. 查找字符首次出现的索引 String str="hello world"; int x=str.indexOf('w'); //返回6 3. 查找字符最后一次出现的索引 int x=str.lastIndexOf('l');/原创 2017-12-15 10:40:45 · 921 阅读 · 0 评论 -
字符串比较
字符串比较 1. 比较是否同一字符串对象 String str1=new String("hello wolrd"); String str2=new String("hello wolrd"); boolean b=(str1==str2); //返回false 2. 比较字符串的内容 boolean b=(str1.equals(str2)); //返回 true 3. 比原创 2017-12-15 10:42:00 · 234 阅读 · 0 评论